From: Sandro Santilli Date: Thu, 20 Dec 2012 17:19:13 +0000 (+0000) Subject: Fix memory leaks in lwsegmentize and cu_ptarray X-Git-Tag: 2.1.0beta2~271 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02214975ccb46cd67c719ac134f30e54d43206cc;p=postgis Fix memory leaks in lwsegmentize and cu_ptarray git-svn-id: http://svn.osgeo.org/postgis/trunk@10871 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_ptarray.c b/liblwgeom/cunit/cu_ptarray.c index 7ad8ba32f..d56446f36 100644 --- a/liblwgeom/cunit/cu_ptarray.c +++ b/liblwgeom/cunit/cu_ptarray.c @@ -199,6 +199,7 @@ static void test_ptarray_append_ptarray(void) wkt = lwgeom_to_text(lwline_as_lwgeom(line1)); CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 10,10 0,11 0)"); lwfree(wkt); + FLAGS_SET_READONLY(line2->points->flags, 0); /* for lwline_free */ lwline_free(line2); lwline_free(line1); @@ -209,6 +210,7 @@ static void test_ptarray_append_ptarray(void) ret = ptarray_append_ptarray(line1->points, line2->points, -1); CU_ASSERT(ret == LW_FAILURE); lwline_free(line2); + FLAGS_SET_READONLY(line1->points->flags, 0); /* for lwline_free */ lwline_free(line1); } @@ -391,7 +393,10 @@ static void test_ptarray_desegmentize() lwgeom_free(out); lwfree(str); - in = lwgeom_segmentize(lwgeom_from_text("COMPOUNDCURVE((0 0, 1 1), CIRCULARSTRING(1 1, 2 2, 3 1), (3 1, 4 4))"),8); + in = lwgeom_from_text("COMPOUNDCURVE((0 0, 1 1), CIRCULARSTRING(1 1, 2 2, 3 1), (3 1, 4 4))"); + out = lwgeom_segmentize(in,8); + lwgeom_free(in); + in = out; out = lwgeom_desegmentize(in); str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL); CU_ASSERT_STRING_EQUAL(str, "COMPOUNDCURVE((0 0,1 1,1 1),CIRCULARSTRING(1 1,1.8049097 1.9807853,3 1),(3 1,4 4))"); @@ -536,7 +541,7 @@ static void test_ptarray_contains_point_arc() CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Two-edge ring made up of semi-circles (really, a circle) */ - lwfree(lwline); + lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0, 0 -1, -1 0)")); pa = lwline->points; @@ -566,7 +571,7 @@ static void test_ptarray_contains_point_arc() CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* One-edge ring, closed circle */ - lwfree(lwline); + lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, -1 0)")); pa = lwline->points; @@ -589,7 +594,7 @@ static void test_ptarray_contains_point_arc() CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Overshort ring */ - lwfree(lwline); + lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0)")); pa = lwline->points; cu_error_msg_reset(); @@ -598,7 +603,7 @@ static void test_ptarray_contains_point_arc() CU_ASSERT_STRING_EQUAL("ptarray_contains_point_arc called with even number of points", cu_error_msg); /* Unclosed ring */ - lwfree(lwline); + lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, 1 0)")); pa = lwline->points; cu_error_msg_reset(); diff --git a/liblwgeom/lwsegmentize.c b/liblwgeom/lwsegmentize.c index bc99de5eb..ad91b2cc7 100644 --- a/liblwgeom/lwsegmentize.c +++ b/liblwgeom/lwsegmentize.c @@ -648,6 +648,8 @@ pta_desegmentize(POINTARRAY *points, int type, int srid) edge_type = edges_in_arcs[i]; } } + lwfree(edges_in_arcs); /* not needed anymore */ + /* Roll out last item */ end = num_edges - 1; lwcollection_add_lwgeom(outcol, geom_from_pa(points, srid, edge_type, start, end)); @@ -656,7 +658,7 @@ pta_desegmentize(POINTARRAY *points, int type, int srid) if ( outcol->ngeoms == 1 ) { LWGEOM *outgeom = outcol->geoms[0]; - lwfree(outcol); + outcol->ngeoms = 0; lwcollection_free(outcol); return outgeom; } return lwcollection_as_lwgeom(outcol);