plpython: fix memory leak

From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: plpython: fix memory leak
Date: 2006-02-20 01:34:47
Message-ID: 1140399287.2615.50.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Attached is a patch that fixes three Python reference leaks in
PLy_traceback(): the objects returned by PyErr_Fetch() are owned by the
caller, so their reference count should be decremented. The memory leak
can be reproduced as follows:

create function import_fail() returns text as
'import foosocket
return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu;

create function test_py() returns void as $$
begin
for i in 1 .. 1000 loop
perform import_fail();
end loop;
return;
end;$$ language plpgsql;

select test_py();

On my system, each invocation of test_py() leaks about 2MB. With the
patch applied, each invocation leaks about 500KB. So obviously there are
some more leaks here -- I searched briefly for additional problems, but
couldn't see anything obvious.

I don't have time at the moment to track down the remaining problems, so
I'd like to apply the patch as-is: I'll come back to the remaining
memory leaks later, unless someone beats me to it.

Barring any objections, I'll apply this patch to HEAD and back branches
tomorrow.

-Neil

Attachment Content-Type Size
plpython_mem_leak-1.patch text/x-patch 978 bytes

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message James William Pye 2006-02-20 01:35:16 Re: ScanDirections
Previous Message Neil Conway 2006-02-20 01:21:31 Re: ScanDirections