RASTER_DEBUGF(3, "Destroying rt_band @ %p", band);
+ /* offline band and has data, free as data is internally owned */
+ if (band->offline && band->data.offline.mem != NULL)
+ rtdealloc(band->data.offline.mem);
+
/* band->data content is externally owned */
/* XXX jorgearevalo: not really... rt_band_from_wkb allocates memory for
* data.mem
}
/**
- * Load offline band's data
+ * Load offline band's data. Loaded data is internally owned
+ * and should not be released by the caller. Data will be
+ * released when band is destroyed with rt_band_destroy().
*
* @param band : the band who's data to get
*
return 1;
}
+ /* band->data.offline.mem not NULL, free first */
+ if (band->data.offline.mem != NULL) {
+ rtdealloc(band->data.offline.mem);
+ band->data.offline.mem = NULL;
+ }
+
band->data.offline.mem = _band->data.mem;
rt_band_destroy(_band);
void* rt_band_get_data(rt_band band);
/**
- * Load offline band's data
+ * Load offline band's data. Loaded data is internally owned
+ * and should not be released by the caller. Data will be
+ * released when band is destroyed with rt_band_destroy().
*
* @param band : the band who's data to get
*
struct rt_extband_t {
uint8_t bandNum; /* 0-based */
char* path; /* externally owned ? */
- void *mem; /* loaded external band data */
+ void *mem; /* loaded external band data, internally owned */
};
struct rt_band_t {
uint16_t height = rt_raster_get_height(raster);
datasize = rt_pixtype_size(pixtype)*width*height;
- mem = malloc(datasize);
+ mem = rtalloc(datasize);
rt_band band = rt_band_new_inline(width, height,
pixtype, hasnodata, nodataval, mem);
for (i=0; i<nbands; ++i)
{
rt_band band = rt_raster_get_band(raster, i);
- void* mem = rt_band_get_data(band);
- if ( mem ) free(mem);
+ if (!rt_band_is_offline(band)) {
+ void* mem = rt_band_get_data(band);
+ if (mem) rtdealloc(mem);
+ }
rt_band_destroy(band);
}
rt_raster_destroy(raster);
height = rt_raster_get_height(raster);
datasize = rt_pixtype_size(PT_8BUI) * width * height;
- mem = malloc(datasize);
+ mem = rtalloc(datasize);
band = rt_band_new_inline(width, height, PT_8BUI, 1, 1, mem);
assert(band);
nodata = rt_band_get_nodata(band);
CHECK_EQUALS(nodata, 0);
- exprset = malloc(cnt * sizeof(rt_reclassexpr));
+ exprset = rtalloc(cnt * sizeof(rt_reclassexpr));
assert(exprset);
for (i = 0; i < cnt; i++) {
- exprset[i] = malloc(sizeof(struct rt_reclassexpr_t));
+ exprset[i] = rtalloc(sizeof(struct rt_reclassexpr_t));
assert(exprset[i]);
if (i == 0) {
CHECK((rtn != -1));
CHECK_EQUALS(val, 255);
- for (i = cnt - 1; i >= 0; i--) free(exprset[i]);
- free(exprset);
+ for (i = cnt - 1; i >= 0; i--) rtdealloc(exprset[i]);
+ rtdealloc(exprset);
deepRelease(raster);
mem = rt_band_get_data(newband);
- if (mem) free(mem);
+ if (mem) rtdealloc(mem);
rt_band_destroy(newband);
}
/* hex to byte */
wkb_len = (int) ceil(((double) strlen(wkb_hex)) / 2);
- wkb = (unsigned char *) malloc(sizeof(unsigned char) * wkb_len);
+ wkb = (unsigned char *) rtalloc(sizeof(unsigned char) * wkb_len);
for (i = 0; i < wkb_len; i++) {
sscanf(pos, "%2hhx", &wkb[i]);
pos += 2;
NULL
);
- free(wkb);
+ rtdealloc(wkb);
CHECK(raster);
CHECK((rt_raster_get_width(raster) == 100));