]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix intra-query memory leak when a SRF returns zero rows.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Oct 2023 18:04:43 +0000 (14:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Oct 2023 18:04:43 +0000 (14:04 -0400)
commit07494a0df9a66219e5f1029de47ecabc34c9cb55
tree2560791a89d6566ff8b5c7be9c5bad608cffe9d0
parentd1537afe3e6e3fe279dbee6d505292d6e38fef5f
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
src/backend/executor/nodeProjectSet.c