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@postgresql.org
Subject: pgsql: Fix memory leaks in PL/Python.
Date: Thu, 05 Nov 2015 18:52:59 +0000
Message-ID: <E1ZuPed-0005C5-Mr@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Fix memory leaks in PL/Python.

Previously, plpython was in the habit of allocating a lot of stuff in
TopMemoryContext, and it was very slipshod about making sure that stuff
got cleaned up; in particular, use of TopMemoryContext as fn_mcxt for
function calls represents an unfixable leak, since we generally don't
know what the called function might have allocated in fn_mcxt.  This
results in session-lifespan leakage in certain usage scenarios, as for
example in a case reported by Ed Behn back in July.

To fix, get rid of all the retail allocations in TopMemoryContext.
All long-lived allocations are now made in sub-contexts that are
associated with specific objects (either pl/python procedures, or
Python-visible objects such as cursors and plans).  We can clean these
up when the associated object is deleted.

I went so far as to get rid of PLy_malloc completely.  There were a
couple of places where it could still have been used safely, but on
the whole it was just an invitation to bad coding.

Haribabu Kommi, based on a draft patch by Heikki Linnakangas;
some further work by me

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/8c75ad436f75fc629b61f601ba884c8f9313c9af

Modified Files
--------------
src/pl/plpython/plpy_cursorobject.c  |   30 +++++---
src/pl/plpython/plpy_cursorobject.h  |    1 +
src/pl/plpython/plpy_exec.c          |    2 +-
src/pl/plpython/plpy_main.c          |   39 +++++++---
src/pl/plpython/plpy_main.h          |    3 +
src/pl/plpython/plpy_planobject.c    |   19 ++---
src/pl/plpython/plpy_planobject.h    |    1 +
src/pl/plpython/plpy_procedure.c     |  118 +++++++++++++----------------
src/pl/plpython/plpy_procedure.h     |    2 +
src/pl/plpython/plpy_spi.c           |   30 ++++++--
src/pl/plpython/plpy_subxactobject.c |   15 +++-
src/pl/plpython/plpy_typeio.c        |  137 ++++++++++++++++------------------
src/pl/plpython/plpy_typeio.h        |    6 +-
src/pl/plpython/plpy_util.c          |   36 ---------
src/pl/plpython/plpy_util.h          |    5 --
15 files changed, 221 insertions(+), 223 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1ZuPed-0005C5-Mr@gemulon.postgresql.org>
Permalink:  ../E1ZuPed-0005C5-Mr@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ZuPed-0005C5-Mr@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 leaks in PL/Python.
  In-Reply-To: <E1ZuPed-0005C5-Mr@gemulon.postgresql.org>
  References: <E1ZuPed-0005C5-Mr@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