pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix memory leakage in plpgsql DO blocks that use cast expression
Date: Mon, 24 Apr 2023 18:20:04 +0000
Message-ID: <E1pr0nD-004iNU-3C@gemulon.postgresql.org> (raw)

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

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/bfa691087eacc6e0fbf1a0d8ee392c3d2ff3cb34

Modified Files
--------------
src/pl/plpgsql/src/pl_exec.c | 95 ++++++++++++++++++++++++++++++--------------
src/pl/plpgsql/src/plpgsql.h |  2 +-
2 files changed, 67 insertions(+), 30 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1pr0nD-004iNU-3C@gemulon.postgresql.org>
Permalink:  ../E1pr0nD-004iNU-3C@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pr0nD-004iNU-3C@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix memory leakage in plpgsql DO blocks that use cast expression
  In-Reply-To: <E1pr0nD-004iNU-3C@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox