After some pretty tedious assembly debugging I've managed to locate the source of my problem. It is probably similar to a bug involving MemoryContext life cycle on IMMUTABLE functions that I struggled with last winter (later fixed by Tom).

This is what happens:

I have an function declared as IMMUTABLE that returns a SETOF tuples. I palloc some data using the context->multi_call_memory_context during the SRF_IS_FIRSTCALL phase and I assign that data to the context->user_fctx.

I obtain the context again using SRF_PERCALL_SETUP() and from that my palloc'ed data. I have verified that I get the exact same pointer. I do, but the memory that it points to is no longer accessible! I get an access fault and I can't even display that memory in the debugger. This tells me that the memory is no longer bound to the process, it must have been free'd up.

What life span does the context->multi_call_memory_context have in case of IMMUTABLE functions that returns SETOF?

Regards,
Thomas Hallgren



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply via email to