From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix two memory leaks around force-storing tuples in slots.
Date: Fri, 19 Apr 2019 18:55:09 +0000
Message-ID: <E1hHYfF-0003fw-Uy@gemulon.postgresql.org> (raw)
Fix two memory leaks around force-storing tuples in slots.
As reported by Tom, when ExecStoreMinimalTuple() had to perform a
conversion to store the minimal tuple in the slot, it forgot to
respect the shouldFree flag, and leaked the tuple into the current
memory context if true. Fix that by freeing the tuple in that case.
Looking at the relevant code made me (Andres) realize that not having
the shouldFree parameter to ExecForceStoreHeapTuple() was a bad
idea. Some callers had to locally implement the necessary logic, and
in one case it was missing, creating a potential per-group leak in
non-hashed aggregation.
The choice to not free the tuple in ExecComputeStoredGenerated() is
not pretty, but not introduced by this commit - I'll start a separate
discussion about it.
Reported-By: Tom Lane
Discussion: https://postgr.es/m/366.1555382816@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/88e6ad3054ddd5aa0dee12e5def2c335fe92a414
Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c | 4 +---
src/backend/commands/trigger.c | 20 ++++++++++----------
src/backend/executor/execTuples.c | 20 ++++++++++++++++++--
src/backend/executor/nodeAgg.c | 2 +-
src/backend/executor/nodeIndexonlyscan.c | 2 +-
src/backend/executor/nodeModifyTable.c | 9 +++++++--
src/include/executor/tuptable.h | 4 +++-
7 files changed, 41 insertions(+), 20 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: andres@anarazel.de
Subject: Re: pgsql: Fix two memory leaks around force-storing tuples in slots.
In-Reply-To: <E1hHYfF-0003fw-Uy@gemulon.postgresql.org>
References: <E1hHYfF-0003fw-Uy@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