Re: Curing plpgsql's memory leaks for statement-lifespan values

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values
Date: 2016-07-22 05:24:51
Message-ID: CAMsr+YEC5dQFsqWgFJhqZT_gs33z9-_2yASyGL+Z9XdHOQ=+JQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 22 July 2016 at 13:24, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:

>
> On 22 July 2016 at 07:02, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
>> In
>>
>> https://www.postgresql.org/message-id/tencent_5C738ECA65BAD6861AA43E8F@qq.com
>> it was pointed out that you could get an intra-function-call memory leak
>> from something like
>>
>> LOOP
>> BEGIN
>> EXECUTE 'bogus command';
>> EXCEPTION WHEN OTHERS THEN
>> END;
>> END LOOP;
>
>
> ...
>
>
>>
>> Another answer is to invent a third per-function memory context intended
>> to hold statement-lifespan variables.
>>
>>
> I've wanted this in the past and been surprised we don't have it, so +1
> from me.
>
> I don't think a few MemoryContextAlloc's are too ugly.
>
> I suggest that in cassert builds, or maybe just CACHE_CLOBBER_ALWAYS, the
> context is reset after each call even when not cleaning up after an error.
> That'll help catch mistakes and leaks.
>

That is, after each statement.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2016-07-22 05:59:31 Re: [BUG] pg_basebackup from disconnected standby fails
Previous Message Craig Ringer 2016-07-22 05:24:07 Re: Curing plpgsql's memory leaks for statement-lifespan values