]> granicus.if.org Git - postgis/commitdiff
Added forgotten explicit freeing of memory and some code cleanup
authorBborie Park <bkpark at ucdavis.edu>
Fri, 19 Aug 2011 22:57:51 +0000 (22:57 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 19 Aug 2011 22:57:51 +0000 (22:57 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7766 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c

index 871c07ea991fa76b22af69551bc0b3d9f3fd2799..d2ac7320e03f23c061f4de6a30c2dc67bfe5e2d4 100644 (file)
@@ -2322,7 +2322,8 @@ int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count) {
  *
  * @return the default set of or requested quantiles for a band
  */
-rt_quantile rt_band_get_quantiles_stream(rt_band band,
+rt_quantile
+rt_band_get_quantiles_stream(rt_band band,
        int exclude_nodata_value, double sample,
        uint64_t cov_count,
        struct quantile_llist **qlls, int *qlls_count,
@@ -2763,6 +2764,7 @@ rt_quantile rt_band_get_quantiles_stream(rt_band band,
        rtn = rtalloc(sizeof(struct rt_quantile_t) * *rtn_count);
        if (NULL == rtn) return NULL;
 
+       RASTER_DEBUGF(3, "returning %d quantiles", *rtn_count);
        for (i = 0, k = 0; i < *qlls_count; i++) {
                qll = &((*qlls)[i]);
 
@@ -2823,6 +2825,7 @@ rt_quantile rt_band_get_quantiles_stream(rt_band band,
                k++;
        }
 
+       RASTER_DEBUG(3, "done");
        return rtn;
 }
 
index 01dc434a1b003f38cc4fe349971dc374bfd95700..f60bcf4ded17cfd6dae662ad29e6a44276bc2e93 100644 (file)
@@ -3808,8 +3808,8 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;
@@ -4257,6 +4257,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                                        SPI_finish();
 
                                        if (bin_width_count) pfree(bin_width);
+                                       pfree(hist);
 
                                        SRF_RETURN_DONE(funcctx);
                                }
@@ -4320,8 +4321,8 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;
@@ -4562,8 +4563,8 @@ Datum RASTER_quantile(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;
@@ -4824,7 +4825,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                        SRF_RETURN_DONE(funcctx);
                }
                cov_count = strtol(tmp, NULL, 10);
-               POSTGIS_RT_DEBUGF(3, "RASTER_quantileCoverage: covcount = %d", covcount);
+               POSTGIS_RT_DEBUGF(3, "RASTER_quantileCoverage: covcount = %d", cov_count);
                pfree(tmp);
 
                /* iterate through rasters of coverage */
@@ -4947,6 +4948,9 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                SPI_finish();
 
                quantile_llist_destroy(&qlls, qlls_count);
+               if (quantiles_count) pfree(quantiles);
+
+               POSTGIS_RT_DEBUGF(3, "%d quantiles returned", count);
 
                /* Store needed information */
                funcctx->user_fctx = covquant;
@@ -4971,8 +4975,8 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;
@@ -5008,6 +5012,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
        }
        /* do when there is no more left */
        else {
+               POSTGIS_RT_DEBUG(3, "done");
                pfree(covquant2);
                SRF_RETURN_DONE(funcctx);
        }
@@ -5181,8 +5186,8 @@ Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;
@@ -5922,8 +5927,8 @@ Datum RASTER_getGDALDrivers(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldcontext);
        }
 
-  /* stuff done on every call of the function */
-  funcctx = SRF_PERCALL_SETUP();
+       /* stuff done on every call of the function */
+       funcctx = SRF_PERCALL_SETUP();
 
        call_cntr = funcctx->call_cntr;
        max_calls = funcctx->max_calls;