agora inbox for pljava-dev@postgresql.org
help / color / mirror / Atom feedSubject: [Pljava-dev] TupleDesc reference leak
Date: Thu, 21 Jun 2012 09:52:31 +0300
Message-ID: <4FE2C4AF.4000700@enterprisedb.com> (raw)
Hi,
A customer ran into the issue reported through the bug tracker,
#1010962:
http://pgfoundry.org/tracker/?func=detail&atid=334&aid=1010962&group_id=1000038.
If a PL/Java function takes a ResultSet as argument, you get warnings like:
WARNING: TupleDesc reference leak: TupleDesc 124e120 (139824,-1) still
referenced
Grepping through the source, there seems to be two places where PL/Java
gets a reference to a TupleDesc by calling lookup_rowtype_tupdsc(), but
fails to release it. One is in HeapTupleHeader.c:
> jobject HeapTupleHeader_getTupleDesc(HeapTupleHeader ht)
> {
> return TupleDesc_create(
> lookup_rowtype_tupdesc(
> HeapTupleHeaderGetTypeId(ht),
> HeapTupleHeaderGetTypMod(ht)));
> }
This is the one that's leaking in the test case posted in the bug
tracker. Fortunately, this is easy to fix. TupleDesc_create() creates a
copy of the tuple descriptor, so we just need to release it after the
call. Patch attached.
The other is in Type.c, in Type_fromOid function:
> if(typeClass != 0)
> {
> TupleDesc tupleDesc = lookup_rowtype_tupdesc_noerror(typeId, -1, true);
> type = (Type)UDT_registerUDT(typeClass, typeId, typeStruct, tupleDesc, false);
> JNI_deleteLocalRef(typeClass);
> goto finally;
> }
I'm not sure what to do about that one. UDT_registerUDT() puts the
TupleDesc Reference to a field in the UDT instance it creates. It's not
clear to me what the lifecycle of that instance is. If we just created a
copy of the TupleDesc, would we leak memory? Can the UDT object persist
over transactions, in which case it holds a dangling pointer to the
TupleDesc?
Anyway, please apply the attached patch, at least.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-tupledesc-leak-1.patch
Type: text/x-diff
Size: 1077 bytes
Desc: not available
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20120621/325cd43f/attachment.bin;
view thread (2+ messages) latest in thread
Message-ID: <4FE2C4AF.4000700@enterprisedb.com>
Permalink: ../4FE2C4AF.4000700@enterprisedb.com/
Also on: postgresql.org/message-id/4FE2C4AF.4000700@enterprisedb.com
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 using the --to and --cc options:
reply via email
To: pljava-dev@postgresql.org
Subject: Re: [Pljava-dev] TupleDesc reference leak
In-Reply-To: <4FE2C4AF.4000700@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox