Re: memory leak in dbase_redo()

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: memory leak in dbase_redo()
Date: 2025-10-09 22:41:52
Message-ID: 680A8193-47B0-48B7-AA68-EB1BC7A69A07@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 9, 2025, at 22:58, Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:
>
> On Thu, Oct 09, 2025 at 08:08:05AM -0400, Andres Freund wrote:
>> And I think it is right. XLOG_DBASE_CREATE_FILE_COPY is careful to
>> pfree(parent_path), but XLOG_DBASE_CREATE_WAL_LOG isn't.
>
> It looks like this was introduced by commit 9e4f914, which was
> back-patched, but the code path in question first appears in v15. So,
> presumably something like the following needs to be back-patched that far.
> I can take care of it unless someone else wants it.
>
> diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
> index 2793fd83771..4d65e8c46c2 100644
> --- a/src/backend/commands/dbcommands.c
> +++ b/src/backend/commands/dbcommands.c
> @@ -3375,6 +3375,7 @@ dbase_redo(XLogReaderState *record)
> parent_path = pstrdup(dbpath);
> get_parent_directory(parent_path);
> recovery_create_dbdir(parent_path, true);
> + pfree(parent_path);
>
> /* Create the database directory with the version file. */
> CreateDirAndVersionFile(dbpath, xlrec->db_id, xlrec->tablespace_id,
>

pstrdup() allocates memory from current context for dest string, so the memory it returns should be free-ed. LGTM.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2025-10-09 22:56:53 Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
Previous Message Michael Paquier 2025-10-09 22:29:51 Re: [PATCH] Add tests for Bitmapset