lwerror("Missing libprotobuf-c");
PG_RETURN_NULL();
#else
- MemoryContext aggcontext;
+ MemoryContext aggcontext, oldcxt = NULL;
struct geobuf_agg_context *ctx;
if (!AggCheckCallContext(fcinfo, &aggcontext))
- lwerror("pgis_asmvt_transfn: called in non-aggregate context");
- MemoryContextSwitchTo(aggcontext);
+ aggcontext = CurrentMemoryContext;
if (PG_ARGISNULL(0)) {
ctx = palloc(sizeof(*ctx));
ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(1));
geobuf_agg_init_context(ctx);
} else {
+ oldcxt = MemoryContextSwitchTo(aggcontext);
ctx = (struct geobuf_agg_context *) PG_GETARG_POINTER(0);
}
ctx->row = PG_GETARG_HEAPTUPLEHEADER(2);
geobuf_agg_transfn(ctx);
+
+ if (oldcxt)
+ MemoryContextSwitchTo(oldcxt);
+
PG_RETURN_POINTER(ctx);
#endif
}
lwerror("Missing libprotobuf-c");
PG_RETURN_NULL();
#else
- MemoryContext aggcontext;
+ MemoryContext aggcontext, oldcxt = NULL;
struct mvt_agg_context *ctx;
if (!AggCheckCallContext(fcinfo, &aggcontext))
- lwerror("pgis_asmvt_transfn: called in non-aggregate context");
- MemoryContextSwitchTo(aggcontext);
+ aggcontext = CurrentMemoryContext;
if (PG_ARGISNULL(0)) {
ctx = palloc(sizeof(*ctx));
PG_FREE_IF_COPY(geom_name, 3);
mvt_agg_init_context(ctx);
} else {
+ oldcxt = MemoryContextSwitchTo(aggcontext);
ctx = (struct mvt_agg_context *) PG_GETARG_POINTER(0);
}
ctx->row = PG_GETARG_HEAPTUPLEHEADER(4);
mvt_agg_transfn(ctx);
+
PG_FREE_IF_COPY(ctx->row, 4);
+ if (oldcxt)
+ MemoryContextSwitchTo(oldcxt);
+
PG_RETURN_POINTER(ctx);
#endif
}
GSERIALIZED *gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
LWGEOM *lwgeom = lwgeom_from_gserialized(gs);
- // TODO: find out why a POSTGIS_DEBUGF affects encoding/uthash (memory issue?)
- //POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %d", layer->n_features);
+ POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %d", layer->n_features);
layer->features[layer->n_features++] = feature;
encode_geometry(ctx, lwgeom);
#endif
#ifndef uthash_fatal
-#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */
+#define uthash_fatal(msg) lwerror("uthash: fatal error (out of memory,etc)")
#endif
#ifndef uthash_malloc
-#define uthash_malloc(sz) malloc(sz) /* malloc fcn */
+#define uthash_malloc(sz) palloc(sz) /* malloc fcn */
#endif
#ifndef uthash_free
-#define uthash_free(ptr,sz) free(ptr) /* free fcn */
+#define uthash_free(ptr,sz) pfree(ptr) /* free fcn */
#endif
#ifndef uthash_strlen
#define uthash_strlen(s) strlen(s)