Skip to content
Browse files

Fixed allocation / check that the functions are executed in aggregate…

… context.
  • Loading branch information...
1 parent 28d8d71 commit 8c648488450ae78e2f3e77332a3677e62b7a48c8 @tvondra committed
Showing with 24 additions and 3 deletions.
  1. +24 −3 src/trimmed.c
View
27 src/trimmed.c
@@ -169,7 +169,14 @@ trimmed_append_double(PG_FUNCTION_ARGS)
double element;
- MemoryContext oldcontext = MemoryContextSwitchTo(CurrentMemoryContext->parent);
+ MemoryContext oldcontext;
+ MemoryContext aggcontext;
+
+ if (! AggCheckCallContext(fcinfo, &aggcontext)) {
+ elog(ERROR, "quantile_append_double called in non-aggregate context");
+ }
+
+ oldcontext = MemoryContextSwitchTo(aggcontext);
if (PG_ARGISNULL(0)) {
@@ -212,7 +219,14 @@ trimmed_append_int32(PG_FUNCTION_ARGS)
int32 element;
- MemoryContext oldcontext = MemoryContextSwitchTo(CurrentMemoryContext->parent);
+ MemoryContext oldcontext;
+ MemoryContext aggcontext;
+
+ if (! AggCheckCallContext(fcinfo, &aggcontext)) {
+ elog(ERROR, "quantile_append_double called in non-aggregate context");
+ }
+
+ oldcontext = MemoryContextSwitchTo(aggcontext);
if (PG_ARGISNULL(0)) {
@@ -256,7 +270,14 @@ trimmed_append_int64(PG_FUNCTION_ARGS)
int64 element;
- MemoryContext oldcontext = MemoryContextSwitchTo(CurrentMemoryContext->parent);
+ MemoryContext oldcontext;
+ MemoryContext aggcontext;
+
+ if (! AggCheckCallContext(fcinfo, &aggcontext)) {
+ elog(ERROR, "quantile_append_double called in non-aggregate context");
+ }
+
+ oldcontext = MemoryContextSwitchTo(aggcontext);
if (PG_ARGISNULL(0)) {

0 comments on commit 8c64848

Please sign in to comment.
Something went wrong with that request. Please try again.