]> granicus.if.org Git - postgis/commitdiff
Refactored rt_raster_replace_band in rt_api.c to return the replaced band.
authorBborie Park <bkpark at ucdavis.edu>
Sat, 11 Jun 2011 04:59:19 +0000 (04:59 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 11 Jun 2011 04:59:19 +0000 (04:59 +0000)
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
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c

index 36a05c59906c1763d246bb900663802e3e8a423b..8128579e0b71c22490b660cbbcfcfc5c23bc810d 100644 (file)
@@ -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;
 }
 
 /**
index 6b3c2c0e58f2932c8d778c47932e722eb2a3907a..ac5c209b073df3f1dc5d52ace588da7586ae4105 100644 (file)
@@ -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);
 
 /**
index fdfff362cb23f51110bd38f59d7f425708267d6f..5081abf60935386010621d6b380bbba66af6eca6 100644 (file)
@@ -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);
index af1ceebc4ba97dac062c39453cf51616c88c9fd1..8778a644e8c352a30965ccda945d166f9684f090 100644 (file)
@@ -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);
        }