Re: memory leak in auto_explain - Mailing list pgsql-hackers

From Tom Lane
Subject Re: memory leak in auto_explain
Date
Msg-id 3754771.1612289622@sss.pgh.pa.us
Whole thread Raw
In response to Re: memory leak in auto_explain  (japin <japinli@hotmail.com>)
Responses Re: memory leak in auto_explain
List pgsql-hackers
japin <japinli@hotmail.com> writes:
> Here's my analysis:
> 1) In the explain_ExecutorEnd(), it will create a ExplainState on SQL function
> memory context, which is a long-lived, cause the memory grow up.

Yeah, agreed.  I think people looking at this have assumed that the
ExecutorEnd hook would automatically be running in the executor's
per-query context, but that's not so; we haven't yet entered
standard_ExecutorEnd where the context switch is.  The caller's
context is likely to be much longer-lived than the executor's.

I think we should put the switch one level further out than you have
it here, just to be sure that InstrEndLoop is covered too (that doesn't
allocate memory, but auto_explain shouldn't assume that).  Otherwise
seems like a good fix.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: bugfix - plpgsql - statement counter is incremented 2x for FOR stmt
Next
From: Tom Lane
Date:
Subject: Re: bugfix - plpgsql - statement counter is incremented 2x for FOR stmt