pgsql: Fix plancache refcount leak after error in ExecuteQuery.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix plancache refcount leak after error in ExecuteQuery.
Date: 2021-06-16 23:30:34
Message-ID: E1ltezS-0003xB-Sm@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9cf163266017ec6d0e190313cce1d417cbf4a549

Modified Files
--------------
src/backend/commands/prepare.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2021-06-17 02:03:00 pgsql: Remove dry-run mode from isolationtester
Previous Message Tomas Vondra 2021-06-16 21:54:40 pgsql: Fix copying data into slots with FDW batching