]> granicus.if.org Git - postgis/commitdiff
#3246, comment in code on the memory behavior of lwcollection_extract()
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 6 Sep 2017 21:00:51 +0000 (21:00 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 6 Sep 2017 21:00:51 +0000 (21:00 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15643 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwcollection.c

index 64fecece9d79b80ead4851e032acddac7724b670..32c04b6f314be2f2471a9854a7c39b86ca174372 100644 (file)
@@ -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);
 
 
index 3c358962cd860d60ce7153412659875d92c82904..cfb6d923f42dcae863b4469c63f13b163647d597 100644 (file)
@@ -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);
                }
        }