Re: Question about MemoryContexts and functions that returns - Mailing list pgsql-hackers

From Thomas Hallgren
Subject Re: Question about MemoryContexts and functions that returns
Date
Msg-id 44209009.3060506@tada.se
Whole thread Raw
In response to Re: Question about MemoryContexts and functions that returns  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Question about MemoryContexts and functions that returns
List pgsql-hackers
Tom Lane wrote:
> Thomas Hallgren <thomas@tada.se> writes:
>   
>> As it turns out, I'm not supposed to allocate the returned tuple in the 
>> caller context.
>>     
>
> Where do you get that from?  plpgsql and plperl both do it that way AFAICS.
>
> Are you testing in an --enable-cassert build?  The memory-clobber
> behavior that that turns on is really essential for finding
> dangling-pointer problems ...
>
>   

I use --enable-cassert. I don't think my problem is a dangling pointer.

I just created a dummy C-function that short circuits the 
java_call_handler. It calls my real java function with the correct 
parameters. When I register this function with language C and use it 
instead of the normal function that calls via the java call handler, 
there's no memory leak. It only leaks memory when I go through the call 
handler. The call handler doesn't execute many lines of code and from 
what I can tell, it doesn't manipulate contexts at all. Nor does it 
allocate anything. Further more, I can prevent the leak by allocating 
the returned tuple in a context of my own and free it on the next call.

Is there a difference in how the executor treat a C function and a 
function using a call handler that can cause this behavior?

Regards,
Thomas Hallgren



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] A real currency type
Next
From: Tom Lane
Date:
Subject: Re: 8.2 planning features