Changeset: 80099c16190e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=80099c16190e
Modified Files:
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
        geom/monetdb5/geom.mal
        geom/monetdb5/geomBulk.c
Branch: sfcgal
Log Message:

Fix a leak. Bulk version for MakePolyong


diffs (113 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -3574,7 +3574,7 @@ wkbEnvelopeFromCoordinates(wkb **out, db
 }
 
 str
-wkbMakePolygon(wkb **out, wkb **external, int *srid)
+wkbMakePolygon(wkb **out, wkb **external, const int *srid)
 {
        GEOSGeom geosGeometry, externalGeometry, linearRingGeometry;
        bit closed = 0;
@@ -5089,9 +5089,13 @@ wkbUnaryCollect(wkb **out, wkb **geoms, 
     }
 
        GEOSSetSRID(geomCollection, srid);
-       *out = geos2wkb(geomCollection);
-    GDKfree(geomGeometries);
-
+    *out = geos2wkb(geomCollection);
+    if (geomGeometries) {
+        for (i = 0; i < num_geoms; i++) {
+            GEOSGeom_destroy(geomGeometries[i]);
+        }
+        GDKfree(geomGeometries);
+    }
        return MAL_SUCCEED;
 }
 
@@ -5101,8 +5105,7 @@ wkbCollectCascade(wkb **outWKB, bat *inB
 {
        BAT *inBAT = NULL;
        BATiter inBAT_iter;
-       BUN i;
-    int j = 0;
+       BUN i = 0;
     wkb *geomWKB = wkbNULL(), **geoms = NULL;
        str err;
 
@@ -5115,7 +5118,6 @@ wkbCollectCascade(wkb **outWKB, bat *inB
     if (!BATcount(inBAT)) {
                BBPunfix(inBAT->batCacheid);
                if ((err = wkbCollect(outWKB,&geomWKB, &geomWKB)) != 
MAL_SUCCEED) {
-                       BBPunfix(inBAT->batCacheid);
                        return err;
                }
         return MAL_SUCCEED;
@@ -5129,11 +5131,11 @@ wkbCollectCascade(wkb **outWKB, bat *inB
                throw(MAL, "geom.Collect", "GDKmalloc failed");
     }
 
-       for (j = 0, i = 0; i < BATcount(inBAT); i++, j++) {
-        geoms[j] = (wkb *) BUNtail(inBAT_iter, i);
+       for (i = 0; i < BATcount(inBAT); i++) {
+        geoms[i] = (wkb *) BUNtail(inBAT_iter, i);
     }
 
-    if ((err = wkbUnaryCollect(outWKB, geoms, j)) != MAL_SUCCEED) {
+    if ((err = wkbUnaryCollect(outWKB, geoms, BATcount(inBAT))) != 
MAL_SUCCEED) {
         BBPunfix(inBAT->batCacheid);
         if (geoms)
             GDKfree(geoms);
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -187,7 +187,8 @@ geom_export str numPointsGeometry(unsign
 geom_export str wkbPointN(wkb **out, wkb **geom, int *n);
 geom_export str wkbEnvelope(wkb **out, wkb **geom);
 geom_export str wkbEnvelopeFromCoordinates(wkb** out, dbl* xmin, dbl* ymin, 
dbl* xmax, dbl* ymax, int* srid);
-geom_export str wkbMakePolygon(wkb** out, wkb** external, int* srid); /*Only 
Polygons without holes*/
+geom_export str wkbMakePolygon(wkb** out, wkb** external, const int* srid); 
/*Only Polygons without holes*/
+geom_export str wkbMakePolygon_bat(bat *outBAT_id, bat *inBAT_id, const int* 
srid); /*Only Polygons without holes*/
 geom_export str wkbMakeLine(wkb**, wkb**, wkb**);
 geom_export str wkbMakeLineAggr(wkb** outWKB, bat* inBAT_id);
 geom_export str wkbsubMakeLine(bat *outBAT_id, bat* bBAT_id, bat *gBAT_id, bat 
*eBAT_id, bit* fla);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -680,6 +680,18 @@ function NPoints(w:bat[:wkb]) :bat[:int]
        return x;
 end NPoints;
 
+command Polygon_bat(w:bat[:wkb], srid:int) :bat[:wkb] address 
wkbMakePolygon_bat
+comment "Returns a Polygon created from the provided LineStrings";
+
+function MakePolygon(w:bat[:wkb]) :bat[:wkb];
+       x := Polygon_bat(w, 0);
+       return x;
+end MakePolygon;
+function MakePolygon(w:bat[:wkb], srid:int) :bat[:wkb];
+       x := Polygon_bat(w, srid);
+       return x;
+end MakePolygon;
+
 command GetCoordinate(w:bat[:wkb], idx:int) :bat[:dbl] address 
wkbGetCoordinate_bat
 comment "Returns the coordinate at position idx of a point, or NULL if not 
available. idx=0 -> X, idx=1 -> Y, idx=2 -> Z. Input must be point";
 function X(w:bat[:wkb]) :bat[:dbl];
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -587,6 +587,12 @@ wkbForceDim_bat(bat *outBAT_id, bat *inB
 {
     return WKBtoWKBflagINT_bat(outBAT_id, inBAT_id, flag, wkbForceDim, 
"batgeom.wkbForceDim");
 }
+
+str
+wkbMakePolygon_bat(bat *outBAT_id, bat *inBAT_id, const int *srid)
+{
+    return WKBtoWKBflagINT_bat(outBAT_id, inBAT_id, srid, wkbMakePolygon, 
"batgeom.wkbMakePolygon");
+}
 /***************************************************************************/
 /*************************** IN: wkb - OUT: bit ****************************/
 /***************************************************************************/
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to