1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Fix several memory leaks when rescanning SRFs. Arrange for an SRF's

"multi_call_ctx" to be a distinct sub-context of the EState's per-query
context, and delete the multi_call_ctx as soon as the SRF finishes
execution. This avoids leaking SRF memory until the end of the current
query, which is particularly egregious when the SRF is scanned
multiple times. This change also fixes a leak of the fields of the
AttInMetadata struct in shutdown_MultiFuncCall().

Also fix a leak of the SRF result TupleDesc when rescanning a
FunctionScan node. The TupleDesc is allocated in the per-query context
for every call to ExecMakeTableFunctionResult(), so we should free it
after calling that function. Since the SRF might choose to return
a non-expendable TupleDesc, we only free the TupleDesc if it is
not being reference-counted.

Backpatch to 8.3 and 8.2 stable branches.
This commit is contained in:
Neil Conway
2008-02-29 02:49:39 +00:00
parent b13635ce59
commit ff428cdeda
2 changed files with 30 additions and 11 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.45 2008/01/01 19:45:49 momjian Exp $
* $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.46 2008/02/29 02:49:39 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@ -77,7 +77,17 @@ FunctionNext(FunctionScanState *node)
* do it always.
*/
if (funcTupdesc)
{
tupledesc_match(node->tupdesc, funcTupdesc);
/*
* If it is a dynamically-allocated TupleDesc, free it: it is
* typically allocated in the EState's per-query context, so we
* must avoid leaking it on rescan.
*/
if (funcTupdesc->tdrefcount == -1)
FreeTupleDesc(funcTupdesc);
}
}
/*