index faa6231d8722d315d7441aa7522eb5b94cfc4cdd..445bb371912171fcf67553a05b7570e7b79a657f 100644 (file)
{
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.)
@@ -424,9 +431,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)