[mapserver-commits] r11281 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sat Mar 19 10:34:43 EDT 2011


Author: rouault
Date: 2011-03-19 07:34:43 -0700 (Sat, 19 Mar 2011)
New Revision: 11281

Modified:
   trunk/mapserver/mapgeos.c
   trunk/mapserver/mapogcfiltercommon.c
   trunk/mapserver/mapprimitive.c
   trunk/mapserver/mapserver.h
Log:
Add msGEOSFreeWKT() to fix memleak and use it

Modified: trunk/mapserver/mapgeos.c
===================================================================
--- trunk/mapserver/mapgeos.c	2011-03-18 20:44:27 UTC (rev 11280)
+++ trunk/mapserver/mapgeos.c	2011-03-19 14:34:43 UTC (rev 11281)
@@ -619,6 +619,7 @@
 #endif
 }
 
+/* Return should be freed with msGEOSFreeWKT */
 char *msGEOSShapeToWKT(shapeObj *shape)
 {
 #ifdef USE_GEOS
@@ -641,6 +642,17 @@
 #endif
 }
 
+void msGEOSFreeWKT(char* pszGEOSWKT)
+{
+#ifdef USE_GEOS
+#if GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 2)
+  GEOSFree(pszGEOSWKT);
+#endif
+#else
+  msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSFreeWKT()");
+#endif
+}
+
 /*
 ** Analytical functions exposed to MapServer/MapScript.
 */

Modified: trunk/mapserver/mapogcfiltercommon.c
===================================================================
--- trunk/mapserver/mapogcfiltercommon.c	2011-03-18 20:44:27 UTC (rev 11280)
+++ trunk/mapserver/mapogcfiltercommon.c	2011-03-19 14:34:43 UTC (rev 11281)
@@ -593,7 +593,7 @@
         pszExpression = msStringConcatenate(pszExpression, pszWktText);
         sprintf(szBuffer, "%s", "')");
         pszExpression = msStringConcatenate(pszExpression, szBuffer);
-        
+        msGEOSFreeWKT(pszWktText);
     }
     if (psBufferShape)
       msFreeShape(psBufferShape);

Modified: trunk/mapserver/mapprimitive.c
===================================================================
--- trunk/mapserver/mapprimitive.c	2011-03-18 20:44:27 UTC (rev 11280)
+++ trunk/mapserver/mapprimitive.c	2011-03-19 14:34:43 UTC (rev 11281)
@@ -74,7 +74,12 @@
 char *msShapeToWKT(shapeObj *shape)
 {
 #ifdef USE_GEOS
-  return msGEOSShapeToWKT(shape);
+  char* pszGEOSStr;
+  char* pszStr;
+  pszGEOSStr = msGEOSShapeToWKT(shape);
+  pszStr = (pszGEOSStr) ? msStrdup(pszGEOSStr) : NULL;
+  msGEOSFreeWKT(pszGEOSStr);
+  return pszStr;
 #elif defined(USE_OGR)
   return msOGRShapeToWKT(shape);
 #else

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2011-03-18 20:44:27 UTC (rev 11280)
+++ trunk/mapserver/mapserver.h	2011-03-19 14:34:43 UTC (rev 11281)
@@ -2411,6 +2411,7 @@
 
 MS_DLL_EXPORT shapeObj *msGEOSShapeFromWKT(const char *string);
 MS_DLL_EXPORT char *msGEOSShapeToWKT(shapeObj *shape);
+MS_DLL_EXPORT void msGEOSFreeWKT(char* pszGEOSWKT);
 
 MS_DLL_EXPORT shapeObj *msGEOSBuffer(shapeObj *shape, double width);
 MS_DLL_EXPORT shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance);



More information about the mapserver-commits mailing list