]> granicus.if.org Git - postgis/commitdiff
Fixed bunch of memory leaks in rt_api.c and testapi.c. Will need to valgrind the...
authorBborie Park <bkpark at ucdavis.edu>
Sat, 11 Jun 2011 00:05:53 +0000 (00:05 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 11 Jun 2011 00:05:53 +0000 (00:05 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7369 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 4339ae429a6325186ef63279926a77efe8879628..36a05c59906c1763d246bb900663802e3e8a423b 100644 (file)
@@ -1770,7 +1770,7 @@ rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample,
                if (inc_vals) {
                        /* free unused memory */
                        if (sample_size != k) {
-                               rtrealloc(values, k * sizeof(double));
+                               values = rtrealloc(values, k * sizeof(double));
                        }
 
                        stats->values = values;
@@ -2208,6 +2208,7 @@ rt_band_get_quantiles(rt_bandstats stats,
 #endif
 
        *rtn_count = quantiles_count;
+       if (init_quantiles) rtdealloc(quantiles);
        RASTER_DEBUG(3, "done");
        return rtn;
 }
@@ -3525,6 +3526,7 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements)
 
         OGR_Fld_Destroy(hFldDfn);
         OGR_DS_DeleteLayer(memdatasource, 0);
+                               if (NULL != pszQuery) rtdealloc(pszQuery);
         OGRReleaseDataSource(memdatasource);
 
         return 0;
@@ -3582,6 +3584,7 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements)
 
     OGR_Fld_Destroy(hFldDfn);
     OGR_DS_DeleteLayer(memdatasource, 0);
+               if (NULL != pszQuery) rtdealloc(pszQuery);
     OGRReleaseDataSource(memdatasource);
 
     return pols;
@@ -5382,7 +5385,7 @@ rt_raster_gdal_drivers(uint32_t *drv_count) {
        }
 
        /* free unused memory */
-       rtrealloc(rtn, j * sizeof(struct rt_gdaldriver_t));
+       rtn = rtrealloc(rtn, j * sizeof(struct rt_gdaldriver_t));
        *drv_count = j;
 
        return rtn;
@@ -5625,6 +5628,8 @@ rt_raster_to_gdal_mem(rt_raster raster, char *srs,
        /* necessary??? */
        GDALFlushCache(ds);
 
+       if (allocBandNums) rtdealloc(bandNums);
+
        return ds;
 }
 
index edc74b63a5afc9a321e794ae55769ccf49efde16..af1ceebc4ba97dac062c39453cf51616c88c9fd1 100644 (file)
@@ -1131,6 +1131,7 @@ static void testBandStats() {
 static void testRasterReplaceBand() {
        rt_raster raster;
        rt_band band;
+       rt_band rband;
        void* mem;
        size_t datasize;
        uint16_t width;
@@ -1140,8 +1141,8 @@ static void testRasterReplaceBand() {
 
        raster = rt_raster_new(10, 10);
        assert(raster); /* or we're out of virtual memory */
-       band = addBand(raster, PT_8BUI, 0, 0);
-       CHECK(band);
+       rband = addBand(raster, PT_8BUI, 0, 0);
+       CHECK(rband);
        band = addBand(raster, PT_8BUI, 1, 255);
        CHECK(band);
 
@@ -1153,14 +1154,19 @@ 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);
        nodata = rt_band_get_nodata(rt_raster_get_band(raster, 0));
        CHECK((nodata == 1));
 
-       rt_band_destroy(band);
-       rt_raster_destroy(raster);
-       free(mem);
+       deepRelease(raster);
+
+       mem = rt_band_get_data(rband);
+       if (mem) free(mem);
+       rt_band_destroy(rband);
 }
 
 struct rt_reclassexpr_t {
@@ -1186,6 +1192,7 @@ static void testBandReclass() {
        int rtn;
        rt_band newband;
        double val;
+       void *mem = NULL;
 
        raster = rt_raster_new(100, 10);
        assert(raster); /* or we're out of virtual memory */
@@ -1254,11 +1261,13 @@ static void testBandReclass() {
        CHECK_EQUALS(val, 255);
 
 
-       for (i = cnt - 1; i >= 0; i--)
-               free(exprset[i]);
+       for (i = cnt - 1; i >= 0; i--) free(exprset[i]);
        free(exprset);
-       rt_band_destroy(newband);
        deepRelease(raster);
+
+       mem = rt_band_get_data(newband);
+       if (mem) free(mem);
+       rt_band_destroy(newband);
 }
 
 struct rt_gdaldriver_t {
@@ -1279,7 +1288,10 @@ 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].create_options);
        }
+
+       rtdealloc(drv);
 }
 
 static void testRasterToGDAL() {