From 34a1aa885585ce58e00f4964e9d510f699b0d2cb Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Fri, 10 Jun 2011 23:01:50 +0000 Subject: [PATCH] Refactored how GDAL warp options are freed. I believe I was prematurely freeing the options. Associated ticket #1015 git-svn-id: http://svn.osgeo.org/postgis/trunk@7367 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 72629f882..4339ae429 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -5940,10 +5940,16 @@ rt_raster_transform(rt_raster raster, char *src_srs, char *dst_srs, numBands = rt_raster_get_num_bands(raster); wopts = GDALCreateWarpOptions(); wopts->padfSrcNoDataReal = (double *) CPLMalloc(numBands * sizeof(double)); - wopts->padfSrcNoDataImag = (double *) CPLMalloc(numBands * sizeof(double)); wopts->padfDstNoDataReal = (double *) CPLMalloc(numBands * sizeof(double)); + wopts->padfSrcNoDataImag = (double *) CPLMalloc(numBands * sizeof(double)); wopts->padfDstNoDataImag = (double *) CPLMalloc(numBands * sizeof(double)); - if (NULL == wopts->padfSrcNoDataReal || NULL == wopts->padfDstNoDataReal) { + if ( + NULL == wopts || + NULL == wopts->padfSrcNoDataReal || + NULL == wopts->padfDstNoDataReal || + NULL == wopts->padfSrcNoDataImag || + NULL == wopts->padfDstNoDataImag + ) { rterror("rt_raster_transform: Out of memory allocating nodata mapping\n"); GDALDestroyWarpOptions(wopts); GDALDeregisterDriver(src_drv); @@ -5963,7 +5969,7 @@ rt_raster_transform(rt_raster raster, char *src_srs, char *dst_srs, if (!rt_band_get_hasnodata_flag(band)) { /* based on line 1004 of gdalwarp.cpp - the problem is that there is a chance that this number is a legitamate value + the problem is that there is a chance that this number is a legitimate value */ wopts->padfSrcNoDataReal[i] = -123456.789; } @@ -5994,9 +6000,10 @@ rt_raster_transform(rt_raster raster, char *src_srs, char *dst_srs, resamplealg, max_err, wopts ); - if (NULL != wopts) GDALDestroyWarpOptions(wopts); + RASTER_DEBUG(3, "Raster reprojected"); if (NULL == dst_ds) { rterror("rt_raster_transform: Unable to transform raster\n"); + if (NULL != wopts) GDALDestroyWarpOptions(wopts); GDALClose(src_ds); GDALDeregisterDriver(src_drv); GDALDestroyDriver(src_drv); @@ -6007,6 +6014,7 @@ rt_raster_transform(rt_raster raster, char *src_srs, char *dst_srs, RASTER_DEBUG(3, "Converting GDAL dataset to raster"); rast = rt_raster_from_gdal_dataset(dst_ds); + if (NULL != wopts) GDALDestroyWarpOptions(wopts); GDALClose(dst_ds); GDALClose(src_ds); GDALDeregisterDriver(src_drv); -- 2.50.1