From: Paul Ramsey Date: Wed, 4 Oct 2017 21:27:43 +0000 (+0000) Subject: Fix memory leak in in-place gridding, when X-Git-Tag: 2.5.0alpha~464 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb46a723030ed8298da5761f7eddfb327a7f7729;p=postgis Fix memory leak in in-place gridding, when 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 --- diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 6d00d0a02..ef2aa75a7 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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;