[postgis-tickets] r15890 - Fix memory leak in in-place gridding, when

Paul Ramsey pramsey at cleverelephant.ca
Wed Oct 4 14:27:43 PDT 2017


Author: pramsey
Date: 2017-10-04 14:27:43 -0700 (Wed, 04 Oct 2017)
New Revision: 15890

Modified:
   trunk/liblwgeom/lwgeom.c
Log:
Fix memory leak in in-place gridding, when
components collapse out of existence, they 
need to be freed (References #3877)


Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c	2017-10-04 20:49:52 UTC (rev 15889)
+++ trunk/liblwgeom/lwgeom.c	2017-10-04 21:27:43 UTC (rev 15890)
@@ -1972,8 +1972,12 @@
 				/* 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 *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;



More information about the postgis-tickets mailing list