aboutsummaryrefslogtreecommitdiff
path: root/contrib/auto_explain/auto_explain.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/auto_explain/auto_explain.c')
-rw-r--r--contrib/auto_explain/auto_explain.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c
index 4167f7f4d54..13d5aa72757 100644
--- a/contrib/auto_explain/auto_explain.c
+++ b/contrib/auto_explain/auto_explain.c
@@ -321,9 +321,16 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
{
if (queryDesc->totaltime && auto_explain_enabled())
{
+ MemoryContext oldcxt;
double msec;
/*
+ * Make sure we operate in the per-query context, so any cruft will be
+ * discarded later during ExecutorEnd.
+ */
+ oldcxt = MemoryContextSwitchTo(queryDesc->estate->es_query_cxt);
+
+ /*
* Make sure stats accumulation is done. (Note: it's okay if several
* levels of hook all do this.)
*/
@@ -370,9 +377,9 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
(errmsg("duration: %.3f ms plan:\n%s",
msec, es->str->data),
errhidestmt(true)));
-
- pfree(es->str->data);
}
+
+ MemoryContextSwitchTo(oldcxt);
}
if (prev_ExecutorEnd)