From: Bborie Park Date: Mon, 13 Jun 2011 21:47:27 +0000 (+0000) Subject: Fixed memory leak in RASTER_asGDALRaster of rt_pg.c and left note in comments of... X-Git-Tag: 2.0.0alpha1~1433 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfdb07ccca7c74a92c69141a5553e8013f678724;p=postgis Fixed memory leak in RASTER_asGDALRaster of rt_pg.c and left note in comments of rt_raster_to_gdal git-svn-id: http://svn.osgeo.org/postgis/trunk@7390 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 054d76827..cb57190aa 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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, diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index d2ba07086..d0c318732 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -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); diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 1817a47d4..b82573e33 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -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); } diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 8778a644e..3ec729a9f 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -1331,6 +1331,8 @@ static void testRasterToGDAL() { fclose(fh); */ + if (gdal) CPLFree(gdal); + deepRelease(raster); }