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

From Robert Haas
Subject Re: Avoid memory leaks during base backups
Date
Msg-id CA+TgmoaOvrzCqgWWGbb+CJz5Wx05LxdD5gLbQQcOw8aimfeehA@mail.gmail.com
Whole thread Raw
In response to Re: Avoid memory leaks during base backups  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Responses Re: Avoid memory leaks during base backups  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
On Thu, Oct 20, 2022 at 6:47 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
> I tried implementing this, please see the attached v7 patch.

I haven't checked this in detail but it looks much more reasonable in
terms of code footprint. However, we should, I think, set backup_state
= NULL and tablespace_map = NULL before deleting the memory context.
As you have it, I believe that if backup_state = (BackupState *)
palloc0(sizeof(BackupState)) fails -- say due to running out of memory
-- then those variables could end up pointing to garbage because the
context had already been reset before initializing them. I don't know
whether it's possible for that to cause any concrete harm, but nulling
out the pointers seems like cheap insurance.

-- 
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: cross-platform pg_basebackup
Next
From: Mikhail Gribkov
Date:
Subject: Re: Nicely exiting PG_TRY and PG_CATCH