From: Sandro Santilli Date: Thu, 24 May 2012 06:41:53 +0000 (+0000) Subject: Do not assume geos allocates using malloc. Reduce memory use too. X-Git-Tag: 2.1.0beta2~972 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1faf8d34858f5d50a32445b6c6274f3a91939fad;p=postgis Do not assume geos allocates using malloc. Reduce memory use too. git-svn-id: http://svn.osgeo.org/postgis/trunk@9817 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 7aec3a35e..1a1c01c1b 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -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);