[postgis-tickets] r15643 - #3246, comment in code on the memory behavior of lwcollection_extract()
Paul Ramsey
pramsey at cleverelephant.ca
Wed Sep 6 14:00:52 PDT 2017
Author: pramsey
Date: 2017-09-06 14:00:51 -0700 (Wed, 06 Sep 2017)
New Revision: 15643
Modified:
trunk/liblwgeom/liblwgeom.h.in
trunk/liblwgeom/lwcollection.c
Log:
#3246, comment in code on the memory behavior of lwcollection_extract()
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in 2017-09-06 20:14:06 UTC (rev 15642)
+++ trunk/liblwgeom/liblwgeom.h.in 2017-09-06 21:00:51 UTC (rev 15643)
@@ -1056,6 +1056,9 @@
******************************************************************/
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);
Modified: trunk/liblwgeom/lwcollection.c
===================================================================
--- trunk/liblwgeom/lwcollection.c 2017-09-06 20:14:06 UTC (rev 15642)
+++ trunk/liblwgeom/lwcollection.c 2017-09-06 21:00:51 UTC (rev 15643)
@@ -362,6 +362,8 @@
/**
* 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 @@
geomlist[geomlistlen] = tmpcol->geoms[j];
geomlistlen++;
}
+ if (tmpcol->geoms)
+ lwfree(tmpcol->geoms);
+ if (tmpcol->bbox)
+ lwfree(tmpcol->bbox);
lwfree(tmpcol);
}
}
More information about the postgis-tickets
mailing list