]> granicus.if.org Git - postgis/commitdiff
#3254, ST_SubDivide garden crash, not empty safe
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 21 Aug 2015 13:37:55 +0000 (13:37 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 21 Aug 2015 13:37:55 +0000 (13:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13969 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom.c

index 04812494a2ab6f1bff0ec2b54b94976349e14a70..f07b4ac15d2bcd08dcb193eebfd0c48b6bd6f89b 100644 (file)
@@ -1995,14 +1995,20 @@ lwgeom_subdivide(const LWGEOM *geom, int maxvertices)
        static int startdepth = 0;
        static int minmaxvertices = 8;
        LWCOLLECTION *col;
-       GBOX clip = *(lwgeom_get_bbox(geom));
+       GBOX clip;
+       
+       col = lwcollection_construct_empty(COLLECTIONTYPE, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom));
+
+       if ( lwgeom_is_empty(geom) )
+               return col;
 
        if ( maxvertices < minmaxvertices )
        {
+               lwcollection_free(col);
                lwerror("%s: cannot subdivide to fewer than %d vertices per output", __func__, minmaxvertices);
        }
-
-       col = lwcollection_construct_empty(COLLECTIONTYPE, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom));
+       
+       clip = *(lwgeom_get_bbox(geom));
        lwgeom_subdivide_recursive(geom, maxvertices, startdepth, col, &clip);
        lwgeom_set_srid((LWGEOM*)col, geom->srid);
        return col;