]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix memory leakage in plpgsql DO blocks that use cast expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Apr 2023 18:19:46 +0000 (14:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Apr 2023 18:19:46 +0000 (14:19 -0400)
commitee71cad9a7c05e705531938f3a92b8bd8ad97ce2
tree08c293f507a10d32ee65ab9efda89b2319f0e5a9
parent082e571c65036a21d5db6d6b9d2b159167b59916
Fix memory leakage in plpgsql DO blocks that use cast expressions.

Commit 04fe805a1 modified plpgsql so that datatype casts make use of
expressions cached by plancache.c, in place of older code where these
expression trees were managed by plpgsql itself.  However, I (tgl)
forgot that we use a separate, shorter-lived cast info hashtable in
DO blocks.  The new mechanism thus resulted in session-lifespan
leakage of the plancache data once a DO block containing one or more
casts terminated.  To fix, split the cast hash table into two parts,
one that tracks only the plancache's CachedExpressions and one that
tracks the expression state trees generated from them.  DO blocks need
their own expression state trees and hence their own version of the
second hash table, but there's no reason they can't share the
CachedExpressions with regular plpgsql functions.

Per report from Ajit Awekar.  Back-patch to v12 where the issue
was introduced.

Ajit Awekar and Tom Lane

Discussion: https://postgr.es/m/CAHv6PyrNaqdvyWUspzd3txYQguFTBSnhx+m6tS06TnM+KWc_LQ@mail.gmail.com
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/plpgsql.h