]> granicus.if.org Git - postgis/commitdiff
Fix memory leaks in lwsegmentize and cu_ptarray
authorSandro Santilli <strk@keybit.net>
Thu, 20 Dec 2012 17:19:13 +0000 (17:19 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 20 Dec 2012 17:19:13 +0000 (17:19 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10871 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_ptarray.c
liblwgeom/lwsegmentize.c

index 7ad8ba32ff843d164059a9802f7f88ad64d4d6b5..d56446f36d664cd9ec1b6196f08b7dcbad384bc6 100644 (file)
@@ -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();
index bc99de5ebf2f0f670811de4788a079c0d98f8375..ad91b2cc73770d495d4a9b97093beec4716ee1b6 100644 (file)
@@ -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);