From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix plancache refcount leak after error in ExecuteQuery.
Date: Wed, 16 Jun 2021 23:30:34 +0000
Message-ID: <E1ltezS-0003xF-T8@gemulon.postgresql.org> (raw)
Fix plancache refcount leak after error in ExecuteQuery.
When stuffing a plan from the plancache into a Portal, one is
not supposed to risk throwing an error between GetCachedPlan and
PortalDefineQuery; if that happens, the plan refcount incremented
by GetCachedPlan will be leaked. I managed to break this rule
while refactoring code in 9dbf2b7d7. There is no visible
consequence other than some memory leakage, and since nobody is
very likely to trigger the relevant error conditions many times
in a row, it's not surprising we haven't noticed. Nonetheless,
it's a bug, so rearrange the order of operations to remove the
hazard.
Noted on the way to looking for a better fix for bug #17053.
This mistake is pretty old, so back-patch to all supported
branches.
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/a6f7745a3e7f89deeb45e78a4bc1b7f39b2d699a
Modified Files
--------------
src/backend/commands/prepare.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix plancache refcount leak after error in ExecuteQuery.
In-Reply-To: <E1ltezS-0003xF-T8@gemulon.postgresql.org>
References: <E1ltezS-0003xF-T8@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