Re: Is there a memory leak in commit 8561e48?

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, "jian(dot)long(at)i-soft(dot)com(dot)cn" <jian(dot)long(at)i-soft(dot)com(dot)cn>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Is there a memory leak in commit 8561e48?
Date: 2018-04-30 21:10:14
Message-ID: f2dfa76b-83e8-75dc-3a75-379ed62b1ded@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 4/27/18 02:44, Andrew Gierth wrote:
>>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
> Tom> I would bet money that that "_SPI_current->internal_xact" thing is
> Tom> wrong/inadequate.
>
> In particular this looks wrong to me: after doing:
>
> do $$
> begin
> execute 'declare foo cursor with hold for select 1/x as a from (values (1),(0)) v(x)';
> commit; -- errors within the commit
> end;
> $$;
> ERROR: division by zero
> CONTEXT: PL/pgSQL function inline_code_block line 1 at COMMIT
>
> the SPI stack is not cleaned up at all, and _SPI_connected is >= 0 even
> when back at the main backend command loop.

The memory leak can be fixed by adding a pfree().

The example you show can be fixed by doing SPI cleanup in both
transaction abort and exception return to main loop, similar to other
cases that now have to handle these separately. Patch attached.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-Fix-SPI-error-cleanup-and-memory-leak.patch text/plain 3.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2018-04-30 21:31:50 EXECUTE does not process parameters
Previous Message Thomas Munro 2018-04-30 21:02:07 Re: [HACKERS] Clock with Adaptive Replacement