From 11052a18c88fe1119adca8c645e70c9031f3f0c4 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 6 Sep 2017 21:00:51 +0000 Subject: [PATCH] #3246, comment in code on the memory behavior of lwcollection_extract() git-svn-id: http://svn.osgeo.org/postgis/trunk@15643 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h.in | 3 +++ liblwgeom/lwcollection.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 64fecece9..32c04b6f3 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1056,6 +1056,9 @@ extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom); ******************************************************************/ LWGEOM *lwcollection_getsubgeom(LWCOLLECTION *col, int gnum); + +/* WARNING: the output will contain references to geometries in the input, */ +/* so the result must be carefully released, not freed. */ LWCOLLECTION* lwcollection_extract(LWCOLLECTION *col, int type); diff --git a/liblwgeom/lwcollection.c b/liblwgeom/lwcollection.c index 3c358962c..cfb6d923f 100644 --- a/liblwgeom/lwcollection.c +++ b/liblwgeom/lwcollection.c @@ -362,6 +362,8 @@ void lwcollection_free(LWCOLLECTION *col) /** * Takes a potentially heterogeneous collection and returns a homogeneous * collection consisting only of the specified type. +* WARNING: the output will contain references to geometries in the input, +* so the result must be carefully released, not freed. */ LWCOLLECTION* lwcollection_extract(LWCOLLECTION *col, int type) { @@ -429,6 +431,10 @@ LWCOLLECTION* lwcollection_extract(LWCOLLECTION *col, int type) geomlist[geomlistlen] = tmpcol->geoms[j]; geomlistlen++; } + if (tmpcol->geoms) + lwfree(tmpcol->geoms); + if (tmpcol->bbox) + lwfree(tmpcol->bbox); lwfree(tmpcol); } } -- 2.40.0