Re: pgsql: Fix small memory leak in get_dbname_oid_list_from_mfile().

From: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Fix small memory leak in get_dbname_oid_list_from_mfile().
Date: 2026-03-16 06:29:51
Message-ID: CAKYtNAosdz3upg7AnrK5m7D107+BdXp2qDVDYFK_8w0DZvP5qg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Thanks Tom for fixing this memory leak.

On Mon, 16 Mar 2026 at 00:54, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Fix small memory leak in get_dbname_oid_list_from_mfile().
>
> Coverity complained that this function leaked the dumpdirpath string,
> which it did. But we don't need to make a copy at all, because
> there's not really any point in trimming trailing slashes from the
> directory name here. If that were needed, the initial
> file_exists_in_directory() test would have failed, since it doesn't
> bother with that (and neither does anyplace else in this file).
> Moreover, if we did want that, reimplementing canonicalize_path()
> poorly is not the way to proceed. Arguably, all of this code should
> be reexamined with an eye to using src/port/path.c's facilities, but
> for today I'll settle for getting rid of the memory leak.
>
> Branch
> ------
> master
>
> Details
> -------
>
https://git.postgresql.org/pg/commitdiff/bb53b8d359d33f10b6274be743c42f6e8ecfbb84
>
> Modified Files
> --------------
> src/bin/pg_dump/pg_restore.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>

We were trimming slashes due to the below test case.

*Ex:*
./pg_dumpall -f dumpdir --format=d

./pg_restore *dumpdir/ *-d postgres -C --format=d --verbose
pg_restore: found database "template1" (OID: 1) in file "*dumpdir//map.dat*"
pg_restore: found database "postgres" (OID: 5) in file "*dumpdir//map.dat*"
pg_restore: found 2 database names in "map.dat"
pg_restore: need to restore 2 databases out of 2 databases

Here, before map.dat, there were 2 slashes so we were trimming slashes.
Please add your opinion for this output.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-03-16 06:45:11 pgsql: Fix accidentally casting away const
Previous Message Amit Kapila 2026-03-16 04:46:58 pgsql: Remove obsolete speculative insert cleanup in ReorderBuffer.