PG_RETURN_BOOL(hasnoband);
}
-/*
- TODO: continue working on adding PG_FREE_IF_COPY from HERE
-*/
-
PG_FUNCTION_INFO_V1(RASTER_mapAlgebraExpr);
Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
+ rt_pgraster *pgrtn = NULL;
rt_raster raster = NULL;
rt_raster newrast = NULL;
rt_band band = NULL;
raster = rt_raster_deserialize(pgraster, FALSE);
if (NULL == raster) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if ( NULL == newrast ) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not create a new raster. "
"Returning NULL");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
{
elog(NOTICE, "Raster is empty. Returning an empty raster");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
elog(NOTICE, "Raster does not have the required band. Returning a raster "
"without a band");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* Get the raster band */
elog(NOTICE, "Could not get the required band. Returning a raster "
"without a band");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/*
if (newpixeltype == PT_END) {
elog(ERROR, "RASTER_mapAlgebraExpr: Invalid pixeltype. Returning NULL");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
ret = rt_raster_generate_new_band(newrast, newpixeltype,
newinitialvalue, TRUE, newnodatavalue, 0);
- /* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
- elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
- "Returning NULL");
- PG_RETURN_NULL();
- }
-
- SET_VARSIZE(pgraster, pgraster->size);
-
/* Free memory */
if (initexpr)
pfree(initexpr);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
+ /* Serialize created raster */
+ pgrtn = rt_raster_serialize(newrast);
rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
+ elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
+ "Returning NULL");
+ PG_RETURN_NULL();
+ }
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
rt_raster_get_num_bands(newrast));
+ if (initexpr)
+ pfree(initexpr);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- if (initexpr)
- pfree(initexpr);
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/**
if (ret != SPI_OK_CONNECT) {
elog(ERROR, "RASTER_mapAlgebraExpr: Unable to connect to the SPI manager."
" Aborting");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
};
/* Free memory allocated out of the current context */
if (SPI_tuptable)
SPI_freetuptable(tuptable);
+ PG_FREE_IF_COPY(pgraster, 0);
SPI_finish();
PG_RETURN_NULL();
/*if (initexpr == NULL || skipcomputation == 2) {*/
if (expression == NULL || skipcomputation == 2) {
+ /* Free memory */
+ if (initexpr)
+ pfree(initexpr);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- /* Free memory */
- if (initexpr)
- pfree(initexpr);
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
RASTER_DEBUG(3, "RASTER_mapAlgebraExpr: Creating new raster band...");
elog(NOTICE, "Could not modify band for new raster. Returning new "
"raster with the original band");
+ if (initexpr)
+ pfree(initexpr);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- if (initexpr)
- pfree(initexpr);
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Main computing loop (%d x %d)",
SPI_finish();
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
SPI_finish();
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
if (initexpr)
pfree(initexpr);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
" Aborting");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
SPI_finish();
pfree(nulls);
pfree(initexpr);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+ rt_raster_destroy(newrast);
+
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster modified, serializing it.");
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
- /* Free memory allocated out of the current context */
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn)
PG_RETURN_NULL();
- }
- SET_VARSIZE(pgraster, pgraster->size);
+ SET_VARSIZE(pgrtn, pgrtn->size);
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster serialized");
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraExpr: returning raster");
- PG_RETURN_POINTER(pgraster);
+ PG_RETURN_POINTER(pgrtn);
}
/*
Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
+ rt_pgraster *pgrtn = NULL;
rt_raster raster = NULL;
rt_raster newrast = NULL;
rt_band band = NULL;
if (NULL == raster)
{
elog(ERROR, "RASTER_mapAlgebraFct: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
"Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
{
elog(NOTICE, "Raster is empty. Returning an empty raster");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraFct: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFct: Getting raster band %d...", nband);
elog(NOTICE, "Raster does not have the required band. Returning a raster "
"without a band");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraFct: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* Get the raster band */
elog(NOTICE, "Could not get the required band. Returning a raster "
"without a band");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraFct: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/*
elog(ERROR, "RASTER_mapAlgebraFct: Invalid pixeltype. Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
elog(ERROR, "RASTER_mapAlgebraFct: Required function is missing. Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
elog(ERROR, "RASTER_mapAlgebraFct: Got invalid function object id. Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
elog(ERROR, "RASTER_mapAlgebraFct: Function provided must return double precision not resultset");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
elog(ERROR, "RASTER_mapAlgebraFct: Function does not have two or three input parameters");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
elog(ERROR, "RASTER_mapAlgebraFct: Strict callback functions cannot have null parameters");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
rt_raster_destroy(newrast);
PG_RETURN_NULL();
ret = rt_raster_generate_new_band(newrast, newpixeltype,
newinitialvalue, TRUE, newnodatavalue, 0);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraFct: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- /* Free memory */
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
elog(NOTICE, "Could not modify band for new raster. Returning new "
"raster with the original band");
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn) {
elog(ERROR, "RASTER_mapAlgebraFct: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
}
- SET_VARSIZE(pgraster, pgraster->size);
-
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFct: Main computing loop (%d x %d)",
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFct: raster modified, serializing it.");
/* Serialize created raster */
- pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+ pgrtn = rt_raster_serialize(newrast);
+ rt_raster_destroy(newrast);
+ if (NULL == pgrtn)
PG_RETURN_NULL();
- }
-
- SET_VARSIZE(pgraster, pgraster->size);
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFct: raster serialized");
- rt_raster_destroy(raster);
- rt_raster_destroy(newrast);
-
POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraFct: returning raster");
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/**
int i = 0;
int j = 0;
- if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+ if (PG_ARGISNULL(0))
+ PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_band: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
default:
elog(ERROR, "RASTER_band: Invalid data type for band number(s)");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
break;
}
rast = rt_raster_from_band(raster, bandNums, j);
pfree(bandNums);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (!rast) {
elog(ERROR, "RASTER_band: Could not create new raster");
PG_RETURN_NULL();
pgrast = rt_raster_serialize(rast);
rt_raster_destroy(rast);
- if (!pgrast) PG_RETURN_NULL();
+ if (!pgrast)
+ PG_RETURN_NULL();
SET_VARSIZE(pgrast, pgrast->size);
PG_RETURN_POINTER(pgrast);
Datum result;
/* pgraster is null, return null */
- if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+ if (PG_ARGISNULL(0))
+ PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_summaryStats: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (sample < 0 || sample > 1) {
elog(NOTICE, "Invalid sample percentage (must be between 0 and 1). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
else if (FLT_EQ(sample, 0.0))
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
stats = rt_band_get_summary_stats(band, (int) exclude_nodata_value, sample, 0, NULL, NULL, NULL);
rt_band_destroy(band);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (NULL == stats) {
elog(NOTICE, "Unable to compute summary statistics for band at index %d. Returning NULL", bandindex);
PG_RETURN_NULL();
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_histogram: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (sample < 0 || sample > 1) {
elog(NOTICE, "Invalid sample percentage (must be between 0 and 1). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
default:
elog(ERROR, "RASTER_histogram: Invalid data type for width");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
break;
elog(NOTICE, "Invalid value for width (must be greater than 0). Returning NULL");
pfree(bin_width);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
stats = rt_band_get_summary_stats(band, (int) exclude_nodata_value, sample, 1, NULL, NULL, NULL);
rt_band_destroy(band);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (NULL == stats || NULL == stats->values) {
elog(NOTICE, "Unable to compute summary statistics for band at index %d", bandindex);
MemoryContextSwitchTo(oldcontext);
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_quantile: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (sample < 0 || sample > 1) {
elog(NOTICE, "Invalid sample percentage (must be between 0 and 1). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
default:
elog(ERROR, "RASTER_quantile: Invalid data type for quantiles");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
break;
elog(NOTICE, "Invalid value for quantile (must be between 0 and 1). Returning NULL");
pfree(quantiles);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
stats = rt_band_get_summary_stats(band, (int) exclude_nodata_value, sample, 1, NULL, NULL, NULL);
rt_band_destroy(band);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (NULL == stats || NULL == stats->values) {
elog(NOTICE, "Could not retrieve summary statistics for band at index %d", bandindex);
MemoryContextSwitchTo(oldcontext);
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
if (!band) {
elog(NOTICE, "Could not find raster band of index %d. Returning NULL", bandindex);
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_valueCount: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
default:
elog(ERROR, "RASTER_valueCount: Invalid data type for values");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
break;
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
vcnts = rt_band_get_value_count(band, (int) exclude_nodata_value, search_values, search_values_count, roundto, NULL, &count);
rt_band_destroy(band);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (NULL == vcnts || !count) {
elog(NOTICE, "Unable to count the values for band at index %d", bandindex);
MemoryContextSwitchTo(oldcontext);
if (bandindex < 1 || bandindex > num_bands) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
if (!band) {
elog(NOTICE, "Could not find band at index %d. Returning NULL", bandindex);
+ rt_raster_destroy(raster);
+
if (SPI_tuptable) SPI_freetuptable(tuptable);
SPI_cursor_close(portal);
SPI_finish();
PG_FUNCTION_INFO_V1(RASTER_reclass);
Datum RASTER_reclass(PG_FUNCTION_ARGS) {
rt_pgraster *pgraster = NULL;
+ rt_pgraster *pgrtn = NULL;
rt_raster raster = NULL;
rt_band band = NULL;
rt_band newband = NULL;
POSTGIS_RT_DEBUG(3, "RASTER_reclass: Starting");
/* pgraster is null, return null */
- if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+ if (PG_ARGISNULL(0))
+ PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* raster */
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_reclass: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
numBands = rt_raster_get_num_bands(raster);
if (!n) {
elog(NOTICE, "Invalid argument for reclassargset. Returning original raster");
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/*
if (NULL == tup) {
elog(NOTICE, "Invalid argument for reclassargset. Returning original raster");
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* band index (1-based) */
if (isnull) {
elog(NOTICE, "Invalid argument for reclassargset. Missing value of nband for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
nband = DatumGetInt32(tupv);
POSTGIS_RT_DEBUGF(3, "RASTER_reclass: expression for band %d", nband);
if (nband < 1 || nband > numBands) {
elog(NOTICE, "Invalid argument for reclassargset. Invalid band index (must use 1-based) for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* reclass expr */
if (isnull) {
elog(NOTICE, "Invalid argument for reclassargset. Missing value of reclassexpr for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
exprtext = (text *) DatumGetPointer(tupv);
if (NULL == exprtext) {
elog(NOTICE, "Invalid argument for reclassargset. Missing value of reclassexpr for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
expr = text_to_cstring(exprtext);
POSTGIS_RT_DEBUGF(5, "RASTER_reclass: expr (raw) %s", expr);
if (comma_n < 1) {
elog(NOTICE, "Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* set of reclass expressions */
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* allocate mem for reclass expression */
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
for (c = 0; c < dash_n; c++) {
for (k = 0; k <= j; k++) pfree(exprset[k]);
pfree(exprset);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/* check interval flags */
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
POSTGIS_RT_DEBUGF(5, "RASTER_reclass: min/max (double) %f", val);
if (isnull) {
elog(NOTICE, "Invalid argument for reclassargset. Missing value of pixeltype for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
pixeltypetext = (text *) DatumGetPointer(tupv);
if (NULL == pixeltypetext) {
elog(NOTICE, "Invalid argument for reclassargset. Missing value of pixeltype for reclassarg of index %d . Returning original raster", i);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
pixeltype = text_to_cstring(pixeltypetext);
POSTGIS_RT_DEBUGF(3, "RASTER_reclass: pixeltype %s", pixeltype);
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
- if (!pgraster) PG_RETURN_NULL();
- SET_VARSIZE(pgraster, pgraster->size);
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
- PG_RETURN_POINTER(pgraster);
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
newband = rt_band_reclass(band, pixtype, hasnodata, nodataval, exprset, j);
if (!newband) {
elog(ERROR, "RASTER_reclass: Could not reclassify raster band of index %d. Returning NULL", nband);
- rt_raster_destroy(raster);
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
PG_RETURN_NULL();
}
/* replace old band with new band */
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);
for (k = 0; k < j; k++) pfree(exprset[k]);
pfree(exprset);
+ rt_band_destroy(newband);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+
PG_RETURN_NULL();
}
pfree(exprset);
}
- pgraster = rt_raster_serialize(raster);
+ pgrtn = rt_raster_serialize(raster);
rt_raster_destroy(raster);
-
- if (!pgraster) PG_RETURN_NULL();
+ PG_FREE_IF_COPY(pgraster, 0);
+ if (!pgrtn)
+ PG_RETURN_NULL();
POSTGIS_RT_DEBUG(3, "RASTER_reclass: Finished");
- SET_VARSIZE(pgraster, pgraster->size);
- PG_RETURN_POINTER(pgraster);
+
+ SET_VARSIZE(pgrtn, pgrtn->size);
+ PG_RETURN_POINTER(pgrtn);
}
/**
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_asGDALRaster: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (PG_ARGISNULL(1)) {
elog(NOTICE, "Format must be provided");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
else {
break;
default:
elog(ERROR, "RASTER_asGDALRaster: Invalid data type for options");
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
break;
}
if (n) {
options = (char **) palloc(sizeof(char *) * (n + 1));
+ if (options == NULL) {
+ elog(ERROR, "RASTER_asGDALRaster: Could not allocate memory for options");
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
+ PG_RETURN_NULL();
+ }
+
/* clean each option */
for (i = 0, j = 0; i < n; i++) {
if (nulls[i]) continue;
pfree(options);
}
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(3, "RASTER_asGDALRaster: Arg 3 (srs) is %s", srs);
}
if (NULL != srs) pfree(srs);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (!gdal) {
elog(ERROR, "RASTER_asGDALRaster: Could not allocate and generate GDAL raster");
elog(ERROR, "RASTER_asRaster: Invalid data type for pixeltype");
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
break;
pfree(pixtypes);
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
}
if (pixtypes_len) pfree(pixtypes);
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
break;
if (values_len) pfree(values);
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
break;
}
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
}
if (options_len) pfree(options);
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUG(3, "RASTER_asRaster: getting wkb of geometry");
wkb = lwgeom_to_wkb(geom, variant, &wkb_len);
lwgeom_free(geom);
+ PG_FREE_IF_COPY(gser, 0);
/* rasterize geometry */
POSTGIS_RT_DEBUG(3, "RASTER_asRaster: rasterizing geometry");
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_resample: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (clamp_srid(src_srid) == SRID_UNKNOWN) {
elog(ERROR, "RASTER_resample: Input raster has unknown (%d) SRID", src_srid);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(4, "source srid: %d", src_srid);
if (clamp_srid(dst_srid) == SRID_UNKNOWN) {
elog(ERROR, "RASTER_resample: %d is an invalid target SRID", dst_srid);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
}
if (NULL == src_srs) {
elog(ERROR, "RASTER_resample: Input raster has unknown SRID (%d)", src_srid);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(4, "src srs: %s", src_srs);
dst_srs = rtpg_getSR(dst_srid);
if (NULL == dst_srs) {
elog(ERROR, "RASTER_resample: Target SRID (%d) is unknown", dst_srid);
- rt_raster_destroy(raster);
if (NULL != src_srs) pfree(src_srs);
+ rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(4, "dst srs: %s", dst_srs);
skew_x, skew_y,
alg, max_err);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
if (NULL != src_srs) pfree(src_srs);
if (NULL != dst_srs) pfree(dst_srs);
if (!rast) {
raster = rt_raster_deserialize(pgraster, TRUE);
if (!raster) {
elog(ERROR, "RASTER_metadata; Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
numBands = rt_raster_get_num_bands(raster);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_bandmetadata: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (numBands < 1) {
elog(NOTICE, "Raster provided has no bands");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
default:
elog(ERROR, "RASTER_bandmetadata: Invalid data type for band number(s)");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
break;
elog(NOTICE, "Invalid band index: %d. Indices must be 1-based. Returning NULL", idx);
pfree(bandNums);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
if (NULL == band) {
elog(NOTICE, "Could not get raster band at index %d", bandNums[i]);
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
}
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
/* Store needed information */
funcctx->user_fctx = bmd;
raster = rt_raster_deserialize(pgraster, TRUE);
if (!raster) {
elog(ERROR, "RASTER_rasterToWorldCoord: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (skewed[i - 1]) {
elog(NOTICE, "Pixel row and column required for computing longitude and latitude of a rotated raster");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
) == 0) {
elog(ERROR, "RASTER_rasterToWorldCoord: Could not compute longitude and latitude from pixel row and column");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
raster = rt_raster_deserialize(pgraster, TRUE);
if (!raster) {
elog(ERROR, "RASTER_worldToRasterCoord: Could not deserialize raster");
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
if (skewed) {
elog(NOTICE, "Latitude and longitude required for computing pixel row and column of a rotated raster");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
) == 0) {
elog(ERROR, "RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
rt_raster_destroy(raster);
+ PG_FREE_IF_COPY(pgraster, 0);
/* force to integer and add one to make 1-based */
cr[0] = ((int) _cr[0]) + 1;
PG_RETURN_DATUM(result);
}
+/*
+ TODO: continue working on adding PG_FREE_IF_COPY from HERE
+*/
+
/**
* See if two rasters intersect
*/