]> granicus.if.org Git - postgis/commitdiff
Fixed bug in lwgeom_explode allocating less memory then needed.
authorSandro Santilli <strk@keybit.net>
Fri, 27 Aug 2004 15:03:11 +0000 (15:03 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 27 Aug 2004 15:03:11 +0000 (15:03 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@760 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_api.c
lwgeom/lwgeom_functions_basic.c

index 74924e5cd31728d61e64b967a0df3ab6f6bc338b..7847aa66c630847fa6ea46df63d8d3fa8ec1af39 100644 (file)
@@ -2671,6 +2671,10 @@ lwgeom_explode(char *serialized)
        result->nlines = 0;
        result->npolys = 0;
 
+#ifdef DEBUG
+       elog(NOTICE, "lwgeom_explode called");
+#endif
+
        if ( ! inspected->ngeometries )
        {
                pfree(result->points);
@@ -2678,6 +2682,10 @@ lwgeom_explode(char *serialized)
                pfree(result->polys);
                result->SRID = -1;
                result->ndims = 0;
+               pfree_inspected(inspected);
+#ifdef DEBUG
+               elog(NOTICE, "lwgeom_explode: no geometries");
+#endif
                return result;
        }
 
@@ -2693,7 +2701,7 @@ lwgeom_explode(char *serialized)
                if ( type == POINTTYPE )
                {
                        result->points = repalloc(result->points,
-                               result->npoints+1);
+                               (result->npoints+1)*sizeof(LWPOINT *));
                        result->points[result->npoints] = subgeom;
                        result->npoints++;
                        continue;
@@ -2702,7 +2710,7 @@ lwgeom_explode(char *serialized)
                if ( type == LINETYPE )
                {
                        result->lines = repalloc(result->lines,
-                               result->nlines+1);
+                               (result->nlines+1)*sizeof(LWLINE *));
                        result->lines[result->nlines] = subgeom;
                        result->nlines++;
                        continue;
@@ -2711,12 +2719,16 @@ lwgeom_explode(char *serialized)
                if ( type == POLYGONTYPE )
                {
                        result->polys = repalloc(result->polys,
-                               result->npolys+1);
+                               (result->npolys+1)*sizeof(LWPOLY *));
                        result->polys[result->npolys] = subgeom;
                        result->npolys++;
                        continue;
                }
 
+#ifdef DEBUG
+               elog(NOTICE, "subtype is %d, recursing", type);
+#endif
+
                // it's a multi geometry, recurse
                subexploded = lwgeom_explode(subgeom);
 
@@ -2766,6 +2778,8 @@ lwgeom_explode(char *serialized)
 
        }
 
+       pfree_inspected(inspected);
+
        return result;
 }
 
index feb836d8fc17604c9053d50148ae1469a02b87f6..632f2f6226dbe141cf3e9561bf741d348491ba28 100644 (file)
@@ -1907,17 +1907,31 @@ dump_lwexploded(LWGEOM_EXPLODED *exploded)
        for (i=0; i<exploded->npoints; i++)
        {
                elog(NOTICE, "Point%d @ %p", i, exploded->points[i]);
+               if ( (int)exploded->points[i] < 100 )
+               {
+                       elog(ERROR, "dirty point pointer");
+               }
        }
 
        for (i=0; i<exploded->nlines; i++)
        {
                elog(NOTICE, "Line%d @ %p", i, exploded->lines[i]);
+               if ( (int)exploded->lines[i] < 100 )
+               {
+                       elog(ERROR, "dirty line pointer");
+               }
        }
 
        for (i=0; i<exploded->npolys; i++)
        {
                elog(NOTICE, "Poly%d @ %p", i, exploded->polys[i]);
+               if ( (int)exploded->polys[i] < 100 )
+               {
+                       elog(ERROR, "dirty poly pointer");
+               }
        }
+
+       return 0;
 }
 
 // collect( geom, geom ) returns a geometry which contains
@@ -1996,7 +2010,12 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        }
 
        //DEBUG
-       dump_lwexploded(expcoll);
+       //elog(NOTICE, "[exp1]");
+       //dump_lwexploded(exp1);
+       //elog(NOTICE, "[exp2]");
+       //dump_lwexploded(exp2);
+       //elog(NOTICE, "[expcoll]");
+       //dump_lwexploded(expcoll);
 
        // Now serialized collected LWGEOM_EXPLODED
        serialized_result = lwexploded_serialize(expcoll, wantbbox);
@@ -2007,7 +2026,9 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
+#ifdef DEBUG
        elog(NOTICE, "Serialized lwexploded"); 
+#endif
 
        // And create LWGEOM type (could provide a _buf version of
        // the serializer instead)