Re: Memory leak in pg_logical_slot_{get,peek}_changes

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Memory leak in pg_logical_slot_{get,peek}_changes
Date: 2024-12-30 17:01:20
Message-ID: CALDaNm2O5iudbCSuQwgA7M9Z-Ou5duSWtz2-_2eh-8xCrjzL0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 30 Dec 2024 at 10:12, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Fri, Dec 27, 2024 at 08:13:53AM +0000, Zhijie Hou (Fujitsu) wrote:
> > Thanks for updating patches ! They look good to me.
>
> Fine by me as well. I had a bit of time today, so I've taken care of
> all this one down to 15 for now after checking each branch.

Thanks for pushing this.

> + cachectx_mcallback = palloc0(sizeof(MemoryContextCallback));
> + cachectx_mcallback->func = pgoutput_cachectx_reset_callback;
> + MemoryContextRegisterResetCallback(ctx->context, cachectx_mcallback);
>
> In the version of the patch for 14 and 13, why don't you just use a
> single reset callback to handle both of cachectx and pubctx at the
> same time? That would be simpler.

Modified

> +/*
> + * Private memory context for relation attribute map, created in
> + * PGOutputData->context when starting pgoutput, and set to NULL when its
> + * parent context is reset via a dedicated MemoryContextCallback.
> + */
> +static MemoryContext cachectx = NULL;
>
> This comment block is a copy-paste of the previous one, let's just
> stick both declarations together.

Modified

> > Just to confirm, would the other stuff (streamed_txns) that allocated under
> > CacheMemoryContext also leaks memory ? I think it's OK to change them
> > separately if it does but just would like to confirm if there is a risk.
>
> Yeah, let's tackle this stuff separately and remove more the
> dependency to CacheMemoryContext.

+1

The attached v3 version has the changes for the same. I have verified
the patch in PG14 and PG13 by attaching to the debugger and calling
"call MemoryContextStats(CacheMemoryContext)" to see there are no
leaks.

Regards,
Vignesh

Attachment Content-Type Size
v3_PG14-0001-Fix-memory-leak-in-pgoutput-relation-attribu.patch text/x-patch 3.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Vatsa 2024-12-30 17:24:21 Re: Query regarding pg_prewarm extension
Previous Message Tom Lane 2024-12-30 16:39:24 Re: RFC: Allow EXPLAIN to Output Page Fault Information