]> granicus.if.org Git - postgis/commitdiff
Do not assume geos allocates using malloc. Reduce memory use too.
authorSandro Santilli <strk@keybit.net>
Thu, 24 May 2012 06:41:53 +0000 (06:41 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 24 May 2012 06:41:53 +0000 (06:41 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9817 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_geos.c

index 7aec3a35edf07448a6ec165361bfb23632199f1d..1a1c01c1b0e92851ea357d76a49edc905092dbde 100644 (file)
@@ -1777,24 +1777,20 @@ Datum isvalidreason(PG_FUNCTION_ARGS)
        {
                reason_str = GEOSisValidReason(g1);
                GEOSGeom_destroy((GEOSGeometry *)g1);
+               if (reason_str == NULL)
+               {
+                       elog(ERROR,"GEOSisValidReason() threw an error: %s", lwgeom_geos_errmsg);
+                       PG_RETURN_NULL(); /* never get here */
+               }
+               result = cstring2text(reason_str);
+               GEOSFree(reason_str);
        }
        else
        {
-               /* we don't use pstrdup here as we free later */
-               reason_str = strdup(lwgeom_geos_errmsg);
+               result = cstring2text(lwgeom_geos_errmsg);
        }
 
 
-       if (reason_str == NULL)
-       {
-               elog(ERROR,"GEOS isvalidreason() threw an error!");
-               PG_RETURN_NULL(); /* never get here */
-       }
-       
-       result = cstring2text(reason_str);
-       /* No pfree because GEOS did a standard malloc on the reason_str */
-       free(reason_str);
-
        PG_FREE_IF_COPY(geom, 0);
        PG_RETURN_POINTER(result);