]> granicus.if.org Git - postgis/commitdiff
Match memory management functions, so that lwalloc is not freed with pfree.
authorDarafei Praliaskouski <me@komzpa.net>
Sun, 14 Oct 2018 23:13:39 +0000 (23:13 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Sun, 14 Oct 2018 23:13:39 +0000 (23:13 +0000)
Currently swapping lwalloc to be malloc instead of palloc results in non-functional build.

git-svn-id: http://svn.osgeo.org/postgis/trunk@16897 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/g_box.c
liblwgeom/lwgeom_api.c
libpgcommon/lwgeom_pg.c
postgis/lwgeom_functions_basic.c
postgis/lwgeom_geos.c
postgis/lwgeom_in_gml.c
postgis/lwgeom_in_kml.c
postgis/lwgeom_inout.c
postgis/lwgeom_ogc.c
postgis/lwgeom_window.c

index 33914bee44961884114348c07c163253e0a01d81..5b6652cebcacabd59b00f940023764a5ad1212a1 100644 (file)
@@ -440,6 +440,7 @@ GBOX* gbox_copy(const GBOX *box)
 void gbox_duplicate(const GBOX *original, GBOX *duplicate)
 {
        assert(duplicate);
+       assert(original);
        memcpy(duplicate, original, sizeof(GBOX));
 }
 
index 67c12071fed7fa7b3497625a0bbb8eaeba22ca3f..27515ee5d95a2038714b838f176b17c49d989e40 100644 (file)
@@ -405,7 +405,7 @@ ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
 {
        uint8_t *ptr;
        assert(n < pa->npoints);
-       ptr=getPoint_internal(pa, n);
+       ptr = getPoint_internal(pa, n);
        switch ( FLAGS_GET_ZM(pa->flags) )
        {
        case 3:
index d4836db47a02b5f6a4de0fcb0e9437d1eefcef8b..1ee41f0cb442518aae7c1fb4b59beb32acdf97b6 100644 (file)
@@ -73,7 +73,6 @@ pg_unparser_errhint(LWGEOM_UNPARSER_RESULT *lwg_unparser_result)
        elog(ERROR, "%s", lwg_unparser_result->message);
 }
 
-
 static void *
 pg_alloc(size_t size)
 {
@@ -169,14 +168,13 @@ pg_install_lwgeom_handlers(void)
 {
        /* install PostgreSQL handlers */
        lwgeom_set_handlers(pg_alloc, pg_realloc, pg_free, pg_error, pg_notice);
+       /*
+       If you want to try with malloc:
+       lwgeom_set_handlers(NULL, NULL, NULL, pg_error, pg_notice);
+       */
        lwgeom_set_debuglogger(pg_debug);
 }
 
-/**
-* Utility method to call the serialization and then set the
-* PgSQL varsize header appropriately with the serialized size.
-*/
-
 /**
 * Utility method to call the serialization and then set the
 * PgSQL varsize header appropriately with the serialized size.
index 6a8c265e0d905e7c1b3834d42beca2734418beb0..98ce3ed4bdc75e3a4c3aeab4a1bd9651f61d9e65 100644 (file)
@@ -143,7 +143,7 @@ Datum LWGEOM_summary(PG_FUNCTION_ARGS)
 
        /* create a text obj to return */
        mytext = cstring_to_text(result);
-       pfree(result);
+       lwfree(result);
 
        PG_FREE_IF_COPY(geom,0);
        PG_RETURN_TEXT_P(mytext);
@@ -2348,7 +2348,7 @@ Datum LWGEOM_asEWKT(PG_FUNCTION_ARGS)
 
        /* Write to text and free the WKT */
        result = cstring_to_text(wkt);
-       pfree(wkt);
+       lwfree(wkt);
 
        /* Return the text */
        PG_FREE_IF_COPY(geom, 0);
index 2219f89b595fb57eb9446e7a05a7d1aa0a5db698..444d4c308ba1f12193d5b4ce6154981851ca0444 100644 (file)
@@ -2936,7 +2936,7 @@ Datum clusterintersecting_garray(PG_FUNCTION_ARGS)
                result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
                GEOSGeom_destroy(geos_results[i]);
        }
-       pfree(geos_results);
+       lwfree(geos_results);
 
        get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
        result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
@@ -3012,7 +3012,7 @@ Datum cluster_within_distance_garray(PG_FUNCTION_ARGS)
                result_array_data[i] = PointerGetDatum(gserialized_from_lwgeom(lw_results[i], NULL));
                lwgeom_free(lw_results[i]);
        }
-       pfree(lw_results);
+       lwfree(lw_results);
 
        get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
        result =  construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
index 0e7f43aea852cb58bbe4831a58b57ddcf560d503..6603a177cca53b64ebeddb0a4b44c1424933455d 100644 (file)
@@ -63,7 +63,7 @@
 
 
 Datum geom_from_gml(PG_FUNCTION_ARGS);
-static LWGEOM* lwgeom_from_gml(const char *wkt);
+static LWGEOM *lwgeom_from_gml(const char *wkt, int xml_size);
 static LWGEOM* parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid);
 
 typedef struct struct_gmlSrs
@@ -102,17 +102,18 @@ Datum geom_from_gml(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom;
        char *xml;
        int root_srid=SRID_UNKNOWN;
-
+       int xml_size;
 
        /* Get the GML stream */
        if (PG_ARGISNULL(0)) PG_RETURN_NULL();
        xml_input = PG_GETARG_TEXT_P(0);
        xml = text_to_cstring(xml_input);
+       xml_size = VARSIZE(xml_input) - VARHDRSZ;
 
        /* Zero for undefined */
        root_srid = PG_GETARG_INT32(1);
 
-       lwgeom = lwgeom_from_gml(xml);
+       lwgeom = lwgeom_from_gml(xml, xml_size);
        if ( root_srid != SRID_UNKNOWN )
                lwgeom->srid = root_srid;
 
@@ -1791,23 +1792,33 @@ static LWGEOM* parse_gml_coll(xmlNodePtr xnode, bool *hasz, int *root_srid)
 /**
  * Read GML
  */
-static LWGEOM* lwgeom_from_gml(const char* xml)
+static LWGEOM *
+lwgeom_from_gml(const char *xml, int xml_size)
 {
        xmlDocPtr xmldoc;
        xmlNodePtr xmlroot=NULL;
-       int xml_size = strlen(xml);
-       LWGEOM *lwgeom;
+       LWGEOM *lwgeom = NULL;
        bool hasz=true;
        int root_srid=SRID_UNKNOWN;
 
        /* Begin to Parse XML doc */
        xmlInitParser();
-        xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
-       if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
+
+       xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
+       if (!xmldoc)
+       {
+               xmlCleanupParser();
+               gml_lwpgerror("invalid GML representation", 1);
+               return NULL;
+       }
+
+       xmlroot = xmlDocGetRootElement(xmldoc);
+       if (!xmlroot)
        {
                xmlFreeDoc(xmldoc);
                xmlCleanupParser();
                gml_lwpgerror("invalid GML representation", 1);
+               return NULL;
        }
 
        lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
@@ -1816,7 +1827,6 @@ static LWGEOM* lwgeom_from_gml(const char* xml)
        xmlCleanupParser();
        /* shouldn't we be releasing xmldoc too here ? */
 
-
        if ( root_srid != SRID_UNKNOWN )
                lwgeom->srid = root_srid;
 
index a3db8dcd65ece94bde0ed9298de30bd4e4398e59..52a7820ef874c4ecd85a82f4ea9421d1d3f4d1d6 100644 (file)
@@ -82,7 +82,6 @@ Datum geom_from_kml(PG_FUNCTION_ARGS)
        bool hasz=true;
        xmlNodePtr xmlroot=NULL;
 
-
        /* Get the KML stream */
        if (PG_ARGISNULL(0)) PG_RETURN_NULL();
        xml_input = PG_GETARG_TEXT_P(0);
index 7bb1b185a1cb86d3678b83bf0196b9aa7fd51d46..dca9639558cbca4db70706acedba0be110022734 100644 (file)
@@ -136,7 +136,7 @@ Datum LWGEOM_in(PG_FUNCTION_ARGS)
                if ( srid ) lwgeom_set_srid(lwgeom, srid);
                /* Add a bbox if necessary */
                if ( lwgeom_needs_bbox(lwgeom) ) lwgeom_add_bbox(lwgeom);
-               pfree(wkb);
+               lwfree(wkb);
                ret = geometry_serialize(lwgeom);
                lwgeom_free(lwgeom);
        }
@@ -322,7 +322,7 @@ Datum LWGEOM_asHEXEWKB(PG_FUNCTION_ARGS)
        SET_VARSIZE(result, text_size);
 
        /* Clean up and return */
-       pfree(hexwkb);
+       lwfree(hexwkb);
        PG_FREE_IF_COPY(geom, 0);
        PG_RETURN_TEXT_P(result);
 }
@@ -351,7 +351,7 @@ Datum LWGEOM_to_text(PG_FUNCTION_ARGS)
 
        /* Copy into text obect */
        result = cstring_to_text(hexwkb);
-       pfree(hexwkb);
+       lwfree(hexwkb);
 
        /* Clean up and return */
        PG_FREE_IF_COPY(geom, 0);
@@ -456,7 +456,7 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
        SET_VARSIZE(result, wkb_size+VARHDRSZ);
 
        /* Clean up and return */
-       pfree(wkb);
+       lwfree(wkb);
        PG_FREE_IF_COPY(geom, 0);
        PG_RETURN_BYTEA_P(result);
 }
index 73a020b359c095629b5427dafa5ca6b348aba700..71c24b466f897da360aeacaaa71b497a9acd647d 100644 (file)
@@ -879,7 +879,7 @@ Datum LWGEOM_asText(PG_FUNCTION_ARGS)
 
        /* Write to text and free the WKT */
        result = cstring_to_text(wkt);
-       pfree(wkt);
+       lwfree(wkt);
 
        /* Return the text */
        PG_FREE_IF_COPY(geom, 0);
@@ -926,7 +926,7 @@ Datum LWGEOM_asBinary(PG_FUNCTION_ARGS)
        result = palloc(wkb_size + VARHDRSZ);
        memcpy(VARDATA(result), wkb, wkb_size);
        SET_VARSIZE(result, wkb_size + VARHDRSZ);
-       pfree(wkb);
+       lwfree(wkb);
 
        /* Return the text */
        PG_FREE_IF_COPY(geom, 0);
index d44b53839fb433229f3e20aa12be6aaaccd36e7a..fe36875f64cee55876fbea68761c2461184ecf06 100644 (file)
@@ -250,7 +250,7 @@ Datum ST_ClusterKMeans(PG_FUNCTION_ARGS)
 
                /* Safe the result */
                memcpy(context->result, r, sizeof(int) * N);
-               pfree(r);
+               lwfree(r);
                context->isdone = true;
        }