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 leak in repeated SPGIST index scans.
Date: Wed, 31 Oct 2018 21:05:21 +0000
Message-ID: <E1gHxg1-0007BI-Hg@gemulon.postgresql.org> (raw)

Fix memory leak in repeated SPGIST index scans.

spgendscan neglected to pfree all the memory allocated by spgbeginscan.
It's possible to get away with that in most normal queries, since the
memory is allocated in the executor's per-query context which is about
to get deleted anyway; but it causes severe memory leakage during
creation or filling of large exclusion-constraint indexes.

Also, document that amendscan is supposed to free what ambeginscan
allocates.  The docs' lack of clarity on that point probably caused this
bug to begin with.  (There is discussion of changing that API spec going
forward, but I don't think it'd be appropriate for the back branches.)

Per report from Bruno Wolff.  It's been like this since the beginning,
so back-patch to all active branches.

In HEAD, also fix an independent leak caused by commit 2a6368343
(allocating memory during spgrescan instead of spgbeginscan, which
might be all right if it got cleaned up, but it didn't).  And do a bit
of code beautification on that commit, too.

Discussion: https://postgr.es/m/20181024012314.GA27428@wolff.to

Branch
------
REL9_3_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/82dd1c271492e7dc4d5b96825f7b29679c5dc33a

Modified Files
--------------
doc/src/sgml/indexam.sgml           | 3 ++-
src/backend/access/spgist/spgscan.c | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1gHxg1-0007BI-Hg@gemulon.postgresql.org>
Permalink:  ../E1gHxg1-0007BI-Hg@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1gHxg1-0007BI-Hg@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 memory leak in repeated SPGIST index scans.
  In-Reply-To: <E1gHxg1-0007BI-Hg@gemulon.postgresql.org>
  References: <E1gHxg1-0007BI-Hg@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