Re: pl/python long-lived allocations in datum->dict transformation - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pl/python long-lived allocations in datum->dict transformation
Date
Msg-id 12683.1331659940@sss.pgh.pa.us
Whole thread Raw
In response to Re: pl/python long-lived allocations in datum->dict transformation  (Jan Urbański <wulczer@wulczer.org>)
List pgsql-hackers
Jan Urbański <wulczer@wulczer.org> writes:
> I came up with a stack of context structures that gets pushed when a
> PL/Python starts being executed and popped when it returns. At first
> they contained just a scratch memory context used by PLyDict_FromTuple.
> Then under the premise of confirming the usefulness of introducing such
> contexts I removed the global PLy_curr_procedure variable and changed
> all users to get the current procedure from the context. It seems to
> have worked, so the total count of global variables is unchanged - hooray!

Applied with some adjustments --- mainly, I thought you were being
too incautious about ensuring that the stack got popped once it'd been
pushed.  The easiest way to fix that was to do the pushes after the
SPI_connect calls, which required decoupling the behavior from
CurrentMemoryContext, which seemed like a good idea anyway.

> While testing I found one more leak, this time caused by allocating a
> structure for caching array type I/O functions and never freeing it.
> Attached as separate patch.

Applied also, but surely if we're leaking memory from the input
descriptors then we should worry about the output ones too?
I made it do that, but if that's wrong, somebody explain why.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Website stylesheet for local docs
Next
From: Alvaro Herrera
Date:
Subject: Re: foreign key locks, 2nd attempt