On Wed, Sep 28, 2022 at 8:46 PM Robert Haas <robertmh...@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
v3-0001-Avoid-memory-leaks-during-backups.patch
Description: Binary data