pgsql: Fix intra-query memory leak when a SRF returns zero rows.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix intra-query memory leak when a SRF returns zero rows.
Date: 2023-10-28 18:05:16
Message-ID: E1qwngS-002nnK-5U@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix intra-query memory leak when a SRF returns zero rows.

When looping around after finding that the set-returning function
returned zero rows for the current input tuple, ExecProjectSet
neglected to reset either of the two memory contexts it's
responsible for cleaning out. Typically this wouldn't cause much
problem, because once the SRF does return at least one row, the
contexts would get reset on the next call. However, if the SRF
returns no rows for many input tuples in succession, quite a lot
of memory could be transiently consumed.

To fix, make sure we reset both contexts while looping around.

Per bug #18172 from Sergei Kornilov. Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18172-9b8c5fc1d676ded3@postgresql.org

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/592cb11fbee08b4cdd660bb45b6767645c9cfdae

Modified Files
--------------
src/backend/executor/nodeProjectSet.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2023-10-29 05:43:46 RE: pg_upgrade test failure
Previous Message Bruce Momjian 2023-10-28 18:03:13 pgsql: doc: add links to Postgres features intro