From: Bborie Park Date: Fri, 19 Aug 2011 22:57:51 +0000 (+0000) Subject: Added forgotten explicit freeing of memory and some code cleanup X-Git-Tag: 2.0.0alpha1~1084 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71aa64ee59b360980ce437d0ea2d449150ed3f3b;p=postgis Added forgotten explicit freeing of memory and some code cleanup git-svn-id: http://svn.osgeo.org/postgis/trunk@7766 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 871c07ea9..d2ac7320e 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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; } diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 01dc434a1..f60bcf4de 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -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;