From e5062e5dc9ac5f9334ea78236bbdff2bde2af7de Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Sat, 11 Jun 2011 04:59:19 +0000 Subject: [PATCH] Refactored rt_raster_replace_band in rt_api.c to return the replaced band. Additional memory cleanups in testapi.c due to segfault and leaks. git-svn-id: http://svn.osgeo.org/postgis/trunk@7372 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 5 ++--- raster/rt_core/rt_api.h | 4 ++-- raster/rt_pg/rt_pg.c | 2 +- raster/test/core/testapi.c | 17 +++++++---------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 36a05c599..8128579e0 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -5174,7 +5174,7 @@ rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count) { * * @return 0 on error or replaced band */ -int +rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index) { rt_band oldband = NULL; assert(NULL != raster); @@ -5197,8 +5197,7 @@ rt_raster_replace_band(rt_raster raster, rt_band band, int index) { raster->bands[index] = band; RASTER_DEBUGF(3, "rt_raster_replace_band: new band at %p", raster->bands[index]); - rt_band_destroy(oldband); - return 1; + return oldband; } /** diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index 6b3c2c0e5..ac5c209b0 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -873,9 +873,9 @@ rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, * @param band : new band to add to raster * @param index : index of band to replace (1-based) * - * @return 0 on error or 1 on success + * @return 0 on error or replaced band */ -int rt_raster_replace_band(rt_raster raster, rt_band band, +rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index); /** diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index fdfff362c..5081abf60 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -4392,7 +4392,7 @@ Datum RASTER_reclass(PG_FUNCTION_ARGS) { } /* replace old band with new band */ - if (rt_raster_replace_band(raster, newband, nband - 1) == 0) { + if (rt_raster_replace_band(raster, newband, nband - 1) == NULL) { elog(ERROR, "RASTER_reclass: Could not replace raster band of index %d with reclassified band. Returning NULL", nband); rt_band_destroy(newband); rt_raster_destroy(raster); diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index af1ceebc4..8778a644e 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -1137,12 +1137,11 @@ static void testRasterReplaceBand() { uint16_t width; uint16_t height; double nodata; - int rtn; raster = rt_raster_new(10, 10); assert(raster); /* or we're out of virtual memory */ - rband = addBand(raster, PT_8BUI, 0, 0); - CHECK(rband); + band = addBand(raster, PT_8BUI, 0, 0); + CHECK(band); band = addBand(raster, PT_8BUI, 1, 255); CHECK(band); @@ -1154,19 +1153,16 @@ static void testRasterReplaceBand() { band = rt_band_new_inline(width, height, PT_8BUI, 1, 1, mem); assert(band); - rband = rt_raster_get_band(raster, 0); - assert(rband); - - rtn = rt_raster_replace_band(raster, band, 0); - CHECK(rtn); + rband = rt_raster_replace_band(raster, band, 0); + CHECK(rband); nodata = rt_band_get_nodata(rt_raster_get_band(raster, 0)); CHECK((nodata == 1)); deepRelease(raster); mem = rt_band_get_data(rband); - if (mem) free(mem); rt_band_destroy(rband); + if (mem) rtdealloc(mem); } struct rt_reclassexpr_t { @@ -1260,7 +1256,6 @@ static void testBandReclass() { CHECK((rtn != -1)); CHECK_EQUALS(val, 255); - for (i = cnt - 1; i >= 0; i--) free(exprset[i]); free(exprset); deepRelease(raster); @@ -1288,6 +1283,8 @@ static void testGDALDrivers() { for (i = 0; i < size; i++) { /*printf("gdal_driver: %s\n", drv[i].short_name);*/ CHECK(drv[i].short_name); + rtdealloc(drv[i].short_name); + rtdealloc(drv[i].long_name); rtdealloc(drv[i].create_options); } -- 2.50.1