[cig-commits] r14855 - cs/spatialdata-0.1/trunk/libsrc/spatialdb

brad at geodynamics.org brad at geodynamics.org
Mon May 4 14:02:29 PDT 2009


Author: brad
Date: 2009-05-04 14:02:29 -0700 (Mon, 04 May 2009)
New Revision: 14855

Modified:
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.cc
Log:
Fixed a few minor memory leaks.

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.cc	2009-05-04 04:28:05 UTC (rev 14854)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.cc	2009-05-04 21:02:29 UTC (rev 14855)
@@ -119,9 +119,6 @@
   assert(0 != pData);
   assert(0 != ppCS);
 
-  // Clear memory and set default values
-  delete *ppCS; *ppCS = new spatialdata::geocoords::CSCart();
-
   utils::LineParser parser(filein, "//");
   parser.eatwhitespace(true);
 
@@ -156,18 +153,18 @@
       buffer.ignore(maxIgnore, '=');
       buffer >> numLocs;
     } else if (0 == strcasecmp(token.c_str(), "value-names")) {
-      if (numValues > 0)
-	names = new std::string[numValues];
-      else
+      if (numValues > 0) {
+	delete[] names; names = new std::string[numValues];
+      } else
 	throw std::runtime_error("Number of values must be specified BEFORE "
 				 "names of values in SimpleDB file.");
       buffer.ignore(maxIgnore, '=');
       for (int iVal=0; iVal < numValues; ++iVal)
 	buffer >> names[iVal];
     } else if (0 == strcasecmp(token.c_str(), "value-units")) {
-      if (numValues > 0)
-	units = new std::string[numValues];
-      else
+      if (numValues > 0) {
+	delete[] units; units = new std::string[numValues];
+      } else
 	throw std::runtime_error("Number of values must be specified BEFORE "
 				 "units of values in SimpleDB file.");
       buffer.ignore(maxIgnore, '=');
@@ -235,6 +232,10 @@
   } // for
   pData->names(const_cast<const char**>(cnames), numValues);
   pData->units(const_cast<const char**>(cunits), numValues);
+  delete[] names; names = 0;
+  delete[] units; units = 0;
+  delete[] cnames; cnames = 0;
+  delete[] cunits; cunits = 0;
 
   for (int iLoc=0; iLoc < numLocs; ++iLoc) {
     buffer.str(parser.next());
@@ -253,6 +254,7 @@
   // number of points
   checkCompatibility(*pData, *ppCS);
   
+  assert(0 != *ppCS);
   (*ppCS)->initialize();
 } // _readV1
 



More information about the CIG-COMMITS mailing list