]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a memory leak in step-39. 3524/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 11 Nov 2016 06:01:26 +0000 (23:01 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 11 Nov 2016 16:01:11 +0000 (09:01 -0700)
Also avoid some obscure old-style C functions.

examples/step-39/step-39.cc

index aa55ccf0fa920f3074e871f630632e11dfdb257a..b51ba0cad988192999574a0f43e102c4027376d7 100644 (file)
@@ -1,6 +1,6 @@
 /* ---------------------------------------------------------------------
  *
- * Copyright (C) 2010 - 2015 by the deal.II authors
+ * Copyright (C) 2010 - 2016 by the deal.II authors
  *
  * This file is part of the deal.II library.
  *
@@ -859,16 +859,16 @@ namespace Step39
   }
 
 
-  // Some graphical output
+  // Create graphical output. We produce the filename by collating the
+  // name from its various components, including the refinement cycle
+  // that we output with two digits.
   template <int dim>
   void InteriorPenaltyProblem<dim>::output_results (const unsigned int cycle) const
   {
-    // Output of the solution in gnuplot format.
-    char *fn = new char[100];
-    sprintf(fn, "sol-%02d", cycle);
+    const std::string filename = "sol-" +
+                                 Utilities::int_to_string(cycle,2) +
+                                 ".gnuplot";
 
-    std::string filename(fn);
-    filename += ".gnuplot";
     deallog << "Writing solution to <" << filename << ">..."
             << std::endl << std::endl;
     std::ofstream gnuplot_output (filename.c_str());

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.