From: Sandro Santilli Date: Thu, 2 Oct 2014 08:03:25 +0000 (+0000) Subject: Fix memory error in ST_ClipByBox2D (#2950) X-Git-Tag: 2.2.0rc1~816 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a26a66ebd196815ec17e1b593e6c4f013e81773;p=postgis Fix memory error in ST_ClipByBox2D (#2950) git-svn-id: http://svn.osgeo.org/postgis/trunk@13028 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_clip_by_rect.c b/liblwgeom/cunit/cu_clip_by_rect.c index f681eb413..e962e3253 100644 --- a/liblwgeom/cunit/cu_clip_by_rect.c +++ b/liblwgeom/cunit/cu_clip_by_rect.c @@ -42,6 +42,14 @@ static void test_lwgeom_clip_by_rect(void) CU_ASSERT_STRING_EQUAL(wkt, tmp) lwfree(tmp); lwgeom_free(out); lwgeom_free(in); + /* Disjoint polygon */ + wkt = "POLYGON((311017 4773762,311016 4773749,311006 4773744,310990 4773748,310980 4773758,310985 4773771,311003 4773776,311017 4773762))"; + in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); + out = lwgeom_clip_by_rect(in, -80, -80, 80, 80); + //tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); lwfree(tmp); + CU_ASSERT(lwgeom_is_empty(out)); + lwgeom_free(out); lwgeom_free(in); + #endif /* POSTGIS_GEOS_VERSION >= 35 */ } diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index ac559fdea..ce3a5092f 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -1671,7 +1671,7 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS) if ( LW_FALSE == gbox_overlaps_2d(bbox1, bbox2) ) { lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0); lwgeom_free(lwgeom1); - PG_FREE_IF_COPY(geom1, 1); + PG_FREE_IF_COPY(geom1, 0); result = geometry_serialize(lwresult) ; lwgeom_free(lwresult) ; PG_RETURN_POINTER(result); diff --git a/regress/clipbybox2d.sql b/regress/clipbybox2d.sql index 1f863de34..1c9a4a6f7 100644 --- a/regress/clipbybox2d.sql +++ b/regress/clipbybox2d.sql @@ -15,4 +15,9 @@ SELECT ST_AsText(ST_ClipByBox2d('POLYGON((0 0,5 4,5 6,0 10,10 10,5 6,5 4,10 0,0 SELECT ST_AsText(ST_ClipByBox2d( '0103000000010000000400000000000000000000000000000000000000000000000000244000000000000000000000000000002440000000000000244000000000000000000000000000002440' , ST_MakeEnvelope(2,2,5,5))); - +-- Geometry disjoint from box, from a table +-- See http://trac.osgeo.org/postgis/ticket/2950 +CREATE TEMPORARY TABLE t AS SELECT +'SRID=3857;POLYGON((41 20,41 0,21 0,1 20,1 40,21 40,41 20))' +::geometry g; +SELECT ST_AsEWKT(ST_ClipByBox2d(g, ST_MakeEnvelope(-20,-20,-10,-10))) FROM t; diff --git a/regress/clipbybox2d_expected b/regress/clipbybox2d_expected index 299e0b6eb..8243e44fa 100644 --- a/regress/clipbybox2d_expected +++ b/regress/clipbybox2d_expected @@ -5,3 +5,4 @@ POINT(2 2) POLYGON((2 2,8 2,2 8,8 8,2 2)) POLYGON((2.5 2,5 4,5 5,5 4,7.5 2,2.5 2)) POLYGON((2 2,2 5,5 5,5 2,2 2)) +SRID=3857;POLYGON EMPTY