diff options
author | Thomas Radke <tradke@aei.mpg.de> | 2005-07-26 12:23:00 +0000 |
---|---|---|
committer | Thomas Radke <tradke@aei.mpg.de> | 2005-07-26 12:23:00 +0000 |
commit | 4b4e7cee5c2580bcf3b47b6af99b0e5bf0e5c9c5 (patch) | |
tree | ad85a3fabb110c510b4a6944405c10c76615d25e /Carpet/CarpetIOScalar | |
parent | 7870aa2629814950096dbb9981405b5d4b0efd73 (diff) |
Carpet{IOScalar,IOHDF5,IOStreamedHDF5}: use C++ strings (rather than Util_asprintf()) to construct C output strings
There was a small memory leak in using Util_asprintf() to continuously append
to an allocated string buffer. The code has now been rewritten to use C++ string
class objects which are destroyed automatically.
This closes http://bugs.carpetcode.org/show_bug.cgi?id=89.
darcs-hash:20050726122331-776a0-874ccd0d5766b85b1110fcd6f501a7e39c35e965.gz
Diffstat (limited to 'Carpet/CarpetIOScalar')
-rw-r--r-- | Carpet/CarpetIOScalar/src/ioscalar.cc | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/Carpet/CarpetIOScalar/src/ioscalar.cc b/Carpet/CarpetIOScalar/src/ioscalar.cc index 2f107287e..1aa7382f2 100644 --- a/Carpet/CarpetIOScalar/src/ioscalar.cc +++ b/Carpet/CarpetIOScalar/src/ioscalar.cc @@ -13,7 +13,6 @@ #include "cctk_Functions.h" #include "cctk_Parameters.h" #include "util_Network.h" -#include "util_String.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "CactusBase/IOUtil/src/ioutil_Utils.h" @@ -595,38 +594,29 @@ namespace CarpetIOScalar { DECLARE_CCTK_PARAMETERS; // re-parse the 'IOScalar::outScalar_vars' parameter if it has changed - if (strcmp (outScalar_vars, IOparameters.out_vars)) - { + if (strcmp (outScalar_vars, IOparameters.out_vars)) { IOUtil_ParseVarsForOutput (cctkGH, CCTK_THORNSTRING, "IOScalar::outScalar_vars", IOparameters.stop_on_parse_errors, outScalar_vars, -1, IOparameters.requests); // notify the user about the new setting - if (! CCTK_Equals (verbose, "none")) - { - char *msg = NULL; - for (int i = CCTK_NumVars () - 1; i >= 0; i--) - { - if (IOparameters.requests[i]) - { - char *fullname = CCTK_FullName (i); - if (! msg) - { - Util_asprintf (&msg, "Periodic scalar output requested for '%s'", - fullname); - } - else - { - Util_asprintf (&msg, "%s, '%s'", msg, fullname); + if (! CCTK_Equals (verbose, "none")) { + int count = 0; + string msg ("Periodic scalar output requested for '"); + for (int i = CCTK_NumVars () - 1; i >= 0; i--) { + if (IOparameters.requests[i]) { + if (count++) { + msg += "', '"; } + char *fullname = CCTK_FullName (i); + msg += fullname; free (fullname); } } - if (msg) - { - CCTK_INFO (msg); - free (msg); + if (count) { + msg += "'"; + CCTK_INFO (msg.c_str()); } } |