]> granicus.if.org Git - postgis/commitdiff
Fixed memory leak in RASTER_asGDALRaster of rt_pg.c and left note in comments of...
authorBborie Park <bkpark at ucdavis.edu>
Mon, 13 Jun 2011 21:47:27 +0000 (21:47 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 13 Jun 2011 21:47:27 +0000 (21:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7390 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c

index 054d76827ffd540e1cbe4c84a1fdb1361e194f35..cb57190aa8dc85a6abd276a62d766bc923f43ed2 100644 (file)
@@ -5209,7 +5209,8 @@ rt_raster_replace_band(rt_raster raster, rt_band band, int index) {
  * @param options : list of format creation options. array of strings
  * @param gdalsize : will be set to the size of returned bytea
  *
- * @return formatted GDAL raster
+ * @return formatted GDAL raster.  the calling function is responsible
+ *   for freeing the returned data using CPLFree()
  */
 uint8_t*
 rt_raster_to_gdal(rt_raster raster, char *srs,
index d2ba070861902630e28bf6d937f8bf61f74fe7bc..d0c3187328a0ee8db17d9a764e1c15ece857ec39 100644 (file)
@@ -887,7 +887,8 @@ rt_band rt_raster_replace_band(rt_raster raster, rt_band band,
  * @param options : list of format creation options. array of strings
  * @param gdalsize : will be set to the size of returned bytea
  *
- * @return formatted GDAL raster
+ * @return formatted GDAL raster.  the calling function is responsible
+ *   for freeing the returned data using CPLFree()
  */
 uint8_t *rt_raster_to_gdal(rt_raster raster, char *srs,
        char *format, char **options, uint64_t *gdalsize);
index 1817a47d40af621612f308b897e2a9847683862f..b82573e33004745f9a775482272a97cd8f73a394 100644 (file)
@@ -4658,8 +4658,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
 
        /* free memory */
        if (NULL != options) {
-               for (i = j - 1; i >= 0; i--)
-                       pfree(options[i]);
+               for (i = j - 1; i >= 0; i--) pfree(options[i]);
                pfree(options);
        }
        rt_raster_destroy(raster);
@@ -4688,6 +4687,9 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
        fclose(fh);
        */
 
+       /* free gdal mem buffer */
+       if (gdal) CPLFree(gdal);
+
        POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Returning pointer to GDAL raster");
        PG_RETURN_POINTER(result);
 }
index 8778a644e8c352a30965ccda945d166f9684f090..3ec729a9f8e56e0dd5d3983cd0bcab5531a7e134 100644 (file)
@@ -1331,6 +1331,8 @@ static void testRasterToGDAL() {
        fclose(fh);
        */
 
+       if (gdal) CPLFree(gdal);
+
        deepRelease(raster);
 }