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 ancient memory leak in contrib/auto_explain.
Date: Tue, 02 Feb 2021 18:49:28 +0000
Message-ID: <E1l70jw-0000pc-Iy@gemulon.postgresql.org> (raw)

Fix ancient memory leak in contrib/auto_explain.

The ExecutorEnd hook is invoked in a context that could be quite
long-lived, not the executor's own per-query context as I think
we were sort of assuming.  Thus, any cruft generated while producing
the EXPLAIN output could accumulate over multiple queries.  This can
result in spectacular leakage if log_nested_statements is on, and
even without that I'm surprised nobody complained before.

To fix, just switch into the executor's context so that anything we
allocate will be released when standard_ExecutorEnd frees the executor
state.  We might as well nuke the code's retail pfree of the explain
output string, too; that's laughably inadequate to the need.

Japin Li, per report from Jeff Janes.  This bug is old, so
back-patch to all supported branches.

Discussion: https://postgr.es/m/CAMkU=1wCVtbeRn0s9gt12KwQ7PLXovbpM8eg25SYocKW3BT4hg@mail.gmail.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2671125c75c04f7abc4a87998959c197e99e34c6

Modified Files
--------------
contrib/auto_explain/auto_explain.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1l70jw-0000pc-Iy@gemulon.postgresql.org>
Permalink:  ../E1l70jw-0000pc-Iy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1l70jw-0000pc-Iy@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 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 ancient memory leak in contrib/auto_explain.
  In-Reply-To: <E1l70jw-0000pc-Iy@gemulon.postgresql.org>
  References: <E1l70jw-0000pc-Iy@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