From: Sandro Santilli Date: Wed, 16 Sep 2015 07:09:47 +0000 (+0000) Subject: Plug leak in lwpoly_make_valid for unclosed ring polygons X-Git-Tag: 2.2.0rc1~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3744875b2fe8835eb3ced3a1c569b60c82d1797;p=postgis Plug leak in lwpoly_make_valid for unclosed ring polygons git-svn-id: http://svn.osgeo.org/postgis/trunk@14075 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_clean.c b/liblwgeom/cunit/cu_clean.c index 035468ce8..df3136542 100644 --- a/liblwgeom/cunit/cu_clean.c +++ b/liblwgeom/cunit/cu_clean.c @@ -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 */ } diff --git a/liblwgeom/lwgeom_geos_clean.c b/liblwgeom/lwgeom_geos_clean.c index 0aac799d2..f37e775cd 100644 --- a/liblwgeom/lwgeom_geos_clean.c +++ b/liblwgeom/lwgeom_geos_clean.c @@ -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 {