]> granicus.if.org Git - postgis/commitdiff
Fix memory leak in in-place gridding, when
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 4 Oct 2017 21:27:43 +0000 (21:27 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 4 Oct 2017 21:27:43 +0000 (21:27 +0000)
components collapse out of existence, they
need to be freed (References #3877)

git-svn-id: http://svn.osgeo.org/postgis/trunk@15890 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom.c

index 6d00d0a0208f7a28b6cf0ba9229a4f1ee2f4558e..ef2aa75a7c2e579a0d87aeadc931e18b58b06a20 100644 (file)
@@ -1972,8 +1972,12 @@ lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
                                /* Skip bad rings */
                                if (pa->npoints < 4)
                                {
-                                       /* If bad ring is external ring, stop everything */
+                                       ptarray_free(pa);
+                                       /* When internal rings collapse, we free */
+                                       /* then and move on */
                                        if (i) continue;
+                                       /* If external ring collapses, we free */
+                                       /* it and stop processing */
                                        else break;
                                }
                                /* Fill in just the rings we are keeping */
@@ -1996,9 +2000,13 @@ lwgeom_grid_in_place(LWGEOM *geom, const gridspec *grid)
                        {
                                LWGEOM *g = col->geoms[i];
                                lwgeom_grid_in_place(g, grid);
-                               /* Skip empty geoms */
+                               /* Empty geoms need to be freed */
+                               /* before we move on */
                                if (lwgeom_is_empty(g))
+                               {
+                                       lwgeom_free(g);
                                        continue;
+                               }
                                col->geoms[j++] = g;
                        }
                        col->ngeoms = j;