[Gdal-dev] memory leaks in MITAB driver
Daniel Morissette
dmorissette at mapgears.com
Mon Jul 9 14:55:04 EDT 2007
Hi Richard,
I'll have a look at this when I have a minute, but to make sure it
doesn't get lost, could you please file a ticket and attach the patch?
Thanks
Daniel
Richard Matsunaga wrote:
> 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;
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
--
Daniel Morissette
http://www.mapgears.com/
More information about the Gdal-dev
mailing list