From: | heikki(dot)linnakangas at enterprisedb(dot)com (Heikki Linnakangas) |
---|---|
To: | |
Subject: | [Pljava-dev] TupleDesc reference leak |
Date: | 2012-06-21 06:52:31 |
Message-ID: | 4FE2C4AF.4000700@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pljava-dev |
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>
From | Date | Subject | |
---|---|---|---|
Next Message | Johann 'Myrkraverk' Oskarsson | 2012-06-21 10:51:46 | [Pljava-dev] TupleDesc reference leak |
Previous Message | Johann 'Myrkraverk' Oskarsson | 2012-06-05 04:53:41 | [Pljava-dev] Blog: Set Returning Functions with PL/Java in PostgreSQL |