From 9ab0cc8f22092d306cd2e5738f40975f827c9f31 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 8 Feb 2012 17:19:53 +0000 Subject: [PATCH] lwgeom_release (#699) move free if copy calls to end of functions in any place where there is any chance that a problem might occur git-svn-id: http://svn.osgeo.org/postgis/trunk@9100 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_functions_basic.c | 2 +- postgis/lwgeom_geos.c | 15 ++++++++++----- postgis/lwgeom_sqlmm.c | 5 ++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 14cef5da4..4883cb7d6 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2204,11 +2204,11 @@ Datum LWGEOM_removepoint(PG_FUNCTION_ARGS) outline = lwline_removepoint(line, which); /* Release memory */ lwline_free(line); - PG_FREE_IF_COPY(pglwg1, 0); result = geometry_serialize((LWGEOM *)outline); lwline_free(outline); + PG_FREE_IF_COPY(pglwg1, 0); PG_RETURN_POINTER(result); } diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 5f4e370b2..031f2b446 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -3397,15 +3397,16 @@ Datum ST_BuildArea(PG_FUNCTION_ARGS) lwgeom_out = lwgeom_buildarea(lwgeom_in); lwgeom_free(lwgeom_in) ; - PG_FREE_IF_COPY(geom, 0); if ( ! lwgeom_out ) { + PG_FREE_IF_COPY(geom, 0); PG_RETURN_NULL(); } result = geometry_serialize(lwgeom_out) ; lwgeom_free(lwgeom_out) ; + PG_FREE_IF_COPY(geom, 0); PG_RETURN_POINTER(result); } @@ -3493,17 +3494,18 @@ Datum ST_Split(PG_FUNCTION_ARGS) lwgeom_out = lwgeom_split(lwgeom_in, lwblade_in); lwgeom_free(lwgeom_in); lwgeom_free(lwblade_in); - PG_FREE_IF_COPY(blade_in, 1); if ( ! lwgeom_out ) { PG_FREE_IF_COPY(in, 0); /* possibly referenced by lwgeom_out */ + PG_FREE_IF_COPY(blade_in, 1); PG_RETURN_NULL(); } out = geometry_serialize(lwgeom_out); lwgeom_free(lwgeom_out); PG_FREE_IF_COPY(in, 0); /* possibly referenced by lwgeom_out */ + PG_FREE_IF_COPY(blade_in, 1); PG_RETURN_POINTER(out); } @@ -3546,17 +3548,19 @@ Datum ST_SharedPaths(PG_FUNCTION_ARGS) lwgeom_out = lwgeom_sharedpaths(g1, g2); lwgeom_free(g1); lwgeom_free(g2); - PG_FREE_IF_COPY(geom1, 0); - PG_FREE_IF_COPY(geom2, 1); if ( ! lwgeom_out ) { + PG_FREE_IF_COPY(geom1, 0); + PG_FREE_IF_COPY(geom2, 1); PG_RETURN_NULL(); } out = geometry_serialize(lwgeom_out); lwgeom_free(lwgeom_out); + PG_FREE_IF_COPY(geom1, 0); + PG_FREE_IF_COPY(geom2, 1); PG_RETURN_POINTER(out); #endif /* POSTGIS_GEOS_VERSION >= 33 */ @@ -3592,16 +3596,17 @@ Datum ST_Node(PG_FUNCTION_ARGS) lwgeom_out = lwgeom_node(g1); lwgeom_free(g1); - PG_FREE_IF_COPY(geom1, 0); if ( ! lwgeom_out ) { + PG_FREE_IF_COPY(geom1, 0); PG_RETURN_NULL(); } out = geometry_serialize(lwgeom_out); lwgeom_free(lwgeom_out); + PG_FREE_IF_COPY(geom1, 0); PG_RETURN_POINTER(out); #endif /* POSTGIS_GEOS_VERSION >= 33 */ diff --git a/postgis/lwgeom_sqlmm.c b/postgis/lwgeom_sqlmm.c index 37d2d57b3..c3da5c64e 100644 --- a/postgis/lwgeom_sqlmm.c +++ b/postgis/lwgeom_sqlmm.c @@ -96,13 +96,16 @@ Datum LWGEOM_line_desegmentize(PG_FUNCTION_ARGS) igeom = lwgeom_from_gserialized(geom); ogeom = lwgeom_desegmentize(igeom); lwgeom_free(igeom); - PG_FREE_IF_COPY(geom, 0); if (ogeom == NULL) + { + PG_FREE_IF_COPY(geom, 0); PG_RETURN_NULL(); + } ret = geometry_serialize(ogeom); lwgeom_free(ogeom); + PG_FREE_IF_COPY(geom, 0); PG_RETURN_POINTER(ret); } -- 2.40.0