Remove memory leak
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jun 2015 17:10:12 +0000 (17:10 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jun 2015 17:10:12 +0000 (17:10 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13746 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwpoly.c

index 2c21e378368451133ac1265760e74191e7687fa3..ef9f1b6fd9aeec137855a84dbebb04962839e761 100644 (file)
@@ -356,7 +356,10 @@ LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed
        LWDEBUGF(2, "%s: simplifying polygon with %d rings", __func__, ipoly->nrings);
 
        if ( lwpoly_is_empty(ipoly) )
+       {
+               lwpoly_free(opoly);
                return NULL;
+       }
 
        for ( i = 0; i < ipoly->nrings; i++ )
        {
@@ -383,14 +386,20 @@ LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed
 
                /* Add ring to simplified polygon */
                if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
+               {
+                       lwpoly_free(opoly);
                        return NULL;
+               }
        }
 
        LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
        opoly->type = ipoly->type;
 
        if( lwpoly_is_empty(opoly) )
+       {
+               lwpoly_free(opoly);
                return NULL;
+       }
 
        return opoly;
 }