]> granicus.if.org Git - postgresql/commit
Fix the plpgsql memory leak exhibited in bug #4677. That leak was introduced
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Apr 2009 02:57:53 +0000 (02:57 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Apr 2009 02:57:53 +0000 (02:57 +0000)
commit03cd7571e880962408fe0d195b31c9ccfab3ed85
treec323e3c5af4f9890179784469dbb1e87b05971ca
parent4703250a766d72366fa511351e247ba74a5d43cd
Fix the plpgsql memory leak exhibited in bug #4677.  That leak was introduced
by my patch of 2007-01-28 to use per-subtransaction ExprContexts/EStates:
since we re-prepared any expression tree when the current subtransaction ID
changed, we'd accumulate more and more leaked expression state trees in the
outermost subtransaction if the same function was executed at multiple levels
of subtransaction nesting.  To fix, go back to the previous scheme where
there was only one EState per transaction for simple plpgsql expressions.
We really only need an ExprContext per subtransaction, not a whole EState,
so it's possible to keep prepared expression state trees in the one EState
throughout the transaction.  This should be more efficient as well as not
leaking memory for cases involving lots of subtransactions.

The added regression test is the case that inspired the 2007-01-28 patch in
the first place, just to make sure we didn't go backwards.  The current
memory leak complaint is unfortunately hard to test for in the regression
test framework, though manual testing shows it's fixed.

Although this is a pre-existing bug, I'm not back-patching because I'd like to
see this method get some field testing first.  Consider back-patching if it
gets through 8.4beta unscathed.
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/plpgsql.h
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql