]> granicus.if.org Git - postgis/commitdiff
Plug leak in lwpoly_make_valid for unclosed ring polygons
authorSandro Santilli <strk@keybit.net>
Wed, 16 Sep 2015 07:09:47 +0000 (07:09 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 16 Sep 2015 07:09:47 +0000 (07:09 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@14075 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_clean.c
liblwgeom/lwgeom_geos_clean.c

index 035468ce8f8a33a063f501f4ae73734e1208f443..df313654289f399af2b2f9c152eabeba5b4ee910 100644 (file)
@@ -130,6 +130,25 @@ static void test_lwgeom_make_valid(void)
        lwgeom_free(gout);
        lwgeom_free(gin);
 
+       /* Test unclosed polygon */
+
+       gin = lwgeom_from_hexwkb(
+"0103000000010000000400000000000000000024400000000000003640000000000000244000000000000040400000000000003440000000000000404000000000000034400000000000003640",
+               LW_PARSER_CHECK_NONE);
+       CU_ASSERT(gin != NULL);
+
+       gout = lwgeom_make_valid(gin);
+       CU_ASSERT(gout != NULL);
+
+       ewkt = lwgeom_to_ewkt(gout);
+       /* printf("c = %s\n", ewkt); */
+       CU_ASSERT_STRING_EQUAL(ewkt,
+"POLYGON((10 22,10 32,20 32,20 22,10 22))");
+       lwfree(ewkt);
+
+       lwgeom_free(gout);
+       lwgeom_free(gin);
+
 #endif /* POSTGIS_GEOS_VERSION >= 33 */
 }
 
index 0aac799d28952066616a3930cf70d2e86b7c71e6..f37e775cd3d5b3262ac757fce774eafea2868160 100644 (file)
@@ -205,12 +205,12 @@ POINTARRAY*
 ring_make_geos_friendly(POINTARRAY* ring)
 {
        POINTARRAY* closedring;
+       POINTARRAY* ring_in = ring;
 
        /* close the ring if not already closed (2d only) */
        closedring = ptarray_close2d(ring);
        if (closedring != ring )
        {
-               ptarray_free(ring); /* should we do this ? */
                ring = closedring;
        }
 
@@ -218,12 +218,14 @@ ring_make_geos_friendly(POINTARRAY* ring)
 
        while ( ring->npoints < 4 )
        {
+               POINTARRAY *oring = ring;
                LWDEBUGF(4, "ring has %d points, adding another", ring->npoints);
                /* let's add another... */
                ring = ptarray_addPoint(ring,
                                        getPoint_internal(ring, 0),
                                        FLAGS_NDIMS(ring->flags),
                                        ring->npoints);
+               if ( oring != ring_in ) ptarray_free(oring);
        }
 
 
@@ -255,10 +257,7 @@ lwpoly_make_geos_friendly(LWPOLY *poly)
                if ( ring_in != ring_out )
                {
                        LWDEBUGF(3, "lwpoly_make_geos_friendly: ring %d cleaned, now has %d points", i, ring_out->npoints);
-                       /* this may come right from
-                        * the binary representation lands
-                        */
-                       /*ptarray_free(ring_in); */
+                       ptarray_free(ring_in);
                }
                else
                {