Re: Avoid memory leaks during base backups - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: Avoid memory leaks during base backups
Date
Msg-id CALj2ACU6XzTv7vxZytGVdvc-fJuRF8-xL7=od8_rz6+TL3xwFg@mail.gmail.com
Whole thread Raw
In response to Re: Avoid memory leaks during base backups  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Avoid memory leaks during base backups
List pgsql-hackers
On Wed, Sep 28, 2022 at 8:46 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> I feel like we ought to be trying to tie
> the cleanup into WalSndErrorCleanup() or WalSndResourceCleanup() based
> on having the memory context that we ought to be blowing away stored
> in a global variable, rather than using a try/catch block.

Okay, I got rid of the try-catch block. I added two clean up callbacks
(one for SQL backup functions or on-line backup, another for base
backup) that basically delete the respective memory contexts and reset
the file-level variables, they get called from PostgresMain()'s error
handling code.

> Like, maybe there's a function EstablishWalSenderMemoryContext() that
> commands can call before allocating memory that shouldn't survive an
> error. And it's deleted after each command if it exists, or if an
> error occurs then WalSndErrorCleanup() deletes it.

I don't think we need any of the above. I've used file-level variables
to hold memory contexts, allocating them whenever needed and cleaning
them up either at the end of backup operation or upon error.

Please review the attached v3 patch.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment

pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: Refactor UnpinBuffer()
Next
From: Bharath Rupireddy
Date:
Subject: Re: Refactor UnpinBuffer()