pgsql: Fix several memory leaks when rescanning SRFs. - Mailing list pgsql-committers

From neilc@postgresql.org (Neil Conway)
Subject pgsql: Fix several memory leaks when rescanning SRFs.
Date
Msg-id 20080229024943.DBCC3754108@cvs.postgresql.org
Whole thread Raw
List 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_3_STABLE

Modified Files:
--------------
    pgsql/src/backend/executor:
        nodeFunctionscan.c (r1.45 -> r1.45.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/executor/nodeFunctionscan.c?r1=1.45&r2=1.45.2.1)
    pgsql/src/backend/utils/fmgr:
        funcapi.c (r1.37 -> r1.37.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/fmgr/funcapi.c?r1=1.37&r2=1.37.2.1)

pgsql-committers by date:

Previous
From: neilc@postgresql.org (Neil Conway)
Date:
Subject: pgsql: Fix several memory leaks when rescanning SRFs.
Next
From: neilc@postgresql.org (Neil Conway)
Date:
Subject: pgsql: Fix several memory leaks when rescanning SRFs.