pgsql: Fix several memory leaks when rescanning SRFs.

From: neilc(at)postgresql(dot)org (Neil Conway)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix several memory leaks when rescanning SRFs.
Date: 2008-02-29 02:49:47
Message-ID: 20080229024947.A1FFA754108@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
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.

Tags:
----
REL8_2_STABLE

Modified Files:
--------------
pgsql/src/backend/executor:
nodeFunctionscan.c (r1.40.2.1 -> r1.40.2.2)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/executor/nodeFunctionscan.c?r1=1.40.2.1&r2=1.40.2.2)
pgsql/src/backend/utils/fmgr:
funcapi.c (r1.31 -> r1.31.2.1)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/fmgr/funcapi.c?r1=1.31&r2=1.31.2.1)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2008-02-29 10:34:51 pgsql: Write the objfiles.txt rules in a way that is compatible with GNU
Previous Message Neil Conway 2008-02-29 02:49:43 pgsql: Fix several memory leaks when rescanning SRFs.