]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix memory leak in Memoize cache key evaluation
authorDavid Rowley <drowley@postgresql.org>
Mon, 20 Mar 2023 00:30:15 +0000 (13:30 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 20 Mar 2023 00:30:15 +0000 (13:30 +1300)
commit8de4660a57e6e165debc949d2cb922f60f8aa921
treeccadab107f280c0d82bcfae01df702abcf02cc77
parent8995eac6c42465c2e866d3670fdb63f7bfbbabc2
Fix memory leak in Memoize cache key evaluation

When probing the Memoize cache to check if the current cache key values
exist in the cache, we perform an evaluation of the expressions making up
the cache key before probing the hash table for those values.  This
operation could leak memory as it is possible that the cache key is an
expression which requires allocation of memory, as was the case in bug
17844.

Here we fix this by correctly switching to the per tuple context before
evaluating the cache expressions so that the memory is freed next time the
per tuple context is reset.

Bug: 17844
Reported-by: Alexey Ermakov
Discussion: https://postgr.es/m/17844-d2f6f9e75a622bed@postgresql.org
Backpatch-through: 14, where Memoize was introduced
src/backend/executor/nodeMemoize.c