Hello,

valgrind'ing my application revealed two memory leaks in msgdataset.cpp.

a) MSGDataset::pszProjection shall always point to a valid string during the lifetime of the object; the old string needs to be released before getting a new one from exportToWkt().

b) A spatial reference is exported to a temporary string as WKT, but the string is never released.


Attached you'll find a patch fixing both; valgrind confirms that both memory leaks are gone.


--
Christian Authmann
Philipps-Universität Marburg
Fachbereich Mathematik und Informatik
AG Datenbanksysteme
Hans-Meerwein-Straße
D-35032 Marburg
--- a/frmts/msg/msgdataset.cpp  2014-04-16 22:04:48.000000000 +0200
+++ b/frmts/msg/msgdataset.cpp  2014-06-26 13:03:19.936803801 +0200
 /************************************************************************/
@@ -248,6 +250,7 @@
 
     poDS->oSRS.SetGEOS(  0, 35785831, 0, 0 );
     poDS->oSRS.SetWellKnownGeogCS( "WGS84" ); // Temporary line to satisfy 
ERDAS (otherwise the ellips is "unnamed"). Eventually this should become the 
custom a and b ellips (CGMS).
+    CPLFree( poDS->pszProjection );
     poDS->oSRS.exportToWkt( &(poDS->pszProjection) );
 
     // The following are 3 different try-outs for also setting the ellips a 
and b parameters.
@@ -276,8 +279,13 @@
 /* -------------------------------------------------------------------- */
 
     char *pszLLTemp;
+    char *pszLLTemp_bak;
+
     (poDS->oSRS.GetAttrNode("GEOGCS"))->exportToWkt(&pszLLTemp);
+    pszLLTemp_bak = pszLLTemp; // importFromWkt() changes the pointer
     poDS->oLL.importFromWkt(&pszLLTemp);
+    CPLFree( pszLLTemp_bak );
+
     poDS->poTransform = OGRCreateCoordinateTransformation( &(poDS->oSRS), 
&(poDS->oLL) );
 
 /* -------------------------------------------------------------------- */
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to