[Gdal-dev] memory leaks in MITAB driver

Richard Matsunaga richard.matsunaga at waypointinfo.com
Mon Jul 9 14:25:30 EDT 2007


I've fixed a few memory leaks in the MITAB driver that have been plaguing me
lately. Hopefully someone more qualified than I can validate these changes
and submit them into the code base.
 
Regards,
Richard
 
 
Index: /ogr/ogrsf_frmts/mitab/mitab_feature.cpp
===================================================================
--- /ogr/ogrsf_frmts/mitab/mitab_feature.cpp (revision 11729)
+++ /ogr/ogrsf_frmts/mitab/mitab_feature.cpp (working copy)
@@ -7813,6 +7813,12 @@
         }
     }
 
+ if (poStyleMgr)
+  delete poStyleMgr;
+
+ if (poStylePart)
+  delete poStylePart;
+
     return;
 }
 
@@ -7997,7 +8003,13 @@
         SetBrushFGColor((GInt32)nBrushColor);
     }
 
-     return;
+ if (poStyleMgr)
+  delete poStyleMgr;
+
+ if (poStylePart)
+  delete poStylePart;
+
+    return;
     
 }  
 
@@ -8281,6 +8293,14 @@
         nSymbolColor = strtol(pszSymbolColor, NULL, 16);
         SetSymbolColor((GInt32)nSymbolColor);
     }
+
+ if (poStyleMgr)
+ {
+  delete poStyleMgr;
+ }
+
+ if (poStylePart)
+  delete poStylePart;
     
     return;
     
     
Index: /ogr/ogrsf_frmts/mitab/mitab_imapinfofile.cpp
===================================================================
--- /ogr/ogrsf_frmts/mitab/mitab_imapinfofile.cpp (revision 11728)
+++ /ogr/ogrsf_frmts/mitab/mitab_imapinfofile.cpp (working copy)
@@ -281,6 +281,7 @@
     TABPoint *poTABPointFeature = NULL;
     TABRegion *poTABRegionFeature = NULL;
     TABPolyline *poTABPolylineFeature = NULL;
+ const char *styleString = NULL;
 
     /*-----------------------------------------------------------------
      * MITAB won't accept new features unless they are in a type derived
@@ -300,11 +301,11 @@
        *------------------------------------------------------------*/
       case wkbPoint:
         poTABFeature = new TABPoint(poFeature->GetDefnRef());
-        if(poFeature->GetStyleString())
+  styleString = poFeature->GetStyleString();
+        if(styleString)
         {
             poTABPointFeature = (TABPoint*)poTABFeature;
-            poTABPointFeature->SetSymbolFromStyleString(
-                poFeature->GetStyleString());
+            poTABPointFeature->SetSymbolFromStyleString(styleString);
         }
         break;
       /*-------------------------------------------------------------
@@ -313,14 +314,13 @@
       case wkbPolygon:
       case wkbMultiPolygon:
         poTABFeature = new TABRegion(poFeature->GetDefnRef());
-        if(poFeature->GetStyleString())
+  styleString = poFeature->GetStyleString();
+        if(styleString)
         {
             poTABRegionFeature = (TABRegion*)poTABFeature;
-            poTABRegionFeature->SetPenFromStyleString(
-                poFeature->GetStyleString());
+            poTABRegionFeature->SetPenFromStyleString(styleString);
 
-            poTABRegionFeature->SetBrushFromStyleString(
-                poFeature->GetStyleString());
+            poTABRegionFeature->SetBrushFromStyleString(styleString);
         }
         break;
       /*-------------------------------------------------------------
@@ -329,11 +329,11 @@
       case wkbLineString:
       case wkbMultiLineString:
         poTABFeature = new TABPolyline(poFeature->GetDefnRef());
-        if(poFeature->GetStyleString())
+  styleString = poFeature->GetStyleString();
+        if(styleString)
         {
             poTABPolylineFeature = (TABPolyline*)poTABFeature;
-            poTABPolylineFeature->SetPenFromStyleString(
-                poFeature->GetStyleString());
+            poTABPolylineFeature->SetPenFromStyleString(styleString);
         }
         break;
       /*-------------------------------------------------------------
@@ -381,6 +381,8 @@
         eErr = OGRERR_FAILURE;
 
     delete poTABFeature;
+ if (styleString != NULL)
+  CPLFree((void *)styleString);
     
     return eErr;
 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070709/d256ab1d/attachment.html


More information about the Gdal-dev mailing list