Re: Fix memory leak in postmasterMain - Mailing list pgsql-hackers

From Henrik TJ
Subject Re: Fix memory leak in postmasterMain
Date
Msg-id 3e890874-8204-e1c2-8def-3a02cbad2232@0x48.dk
Whole thread
In response to Fix memory leak in postmasterMain  (Henrik TJ <henrik@0x48.dk>)
List pgsql-hackers
Hi

On Sat, 21 Feb 2026, Henrik TJ wrote:

> This is fairly inconsequential as memory leaks goes, but if -D is used when 
> starting postgres, the memory allocated by stdrup() will never be freed. 
> Found with valgrind.

Rebased version of this patch attached.

To see valgrind catch the leak:

1. Compile with valgrind.
2. Run postgres with valgrind:
    valgrind --leak-check=full ./pgrun/bin/postgres -D pgdata/

The -D argument is required, as it is the argument from there that does 
not get freed. This should yield:

==444240== 8 bytes in 1 blocks are definitely lost in loss record 29 of 849
==444240==    at 0x4840B26: malloc (vg_replace_malloc.c:447)
==444240==    by 0x5114A2E: strdup (strdup.c:42)
==444240==    by 0x6B7CE0: PostmasterMain (../src/backend/postmaster/postmaster.c:656)
==444240==    by 0x602555: main (../src/backend/main/main.c:231)


   best regards, Henrik
Attachment

pgsql-hackers by date:

Previous
From: Melanie Plageman
Date:
Subject: Re: Two issues leading to discrepancies in FSM data on the standby server
Next
From: Tatsuya Kawata
Date:
Subject: Re: [PATCH] Doc: Fix missing func_signature role in pg_get_tablespace_ddl entry