public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: Andres Freund <[email protected]>
Cc: Fujii Masao <[email protected]>
Cc: Henrik TJ <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Fix memory leak in postmasterMain
Date: Thu, 23 Apr 2026 13:22:04 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <mwikkx643zp3f5qmx27crf2d2ngwgupc4om4kfq4gyc6vukjom@kyimpnconhdv>
References: <[email protected]>
<[email protected]>
<[email protected]>
<CAHGQGwEn3oEad-wR1XoEbe1R-pB1EOycRKjEj+5Pp38mjgiF+Q@mail.gmail.com>
<mwikkx643zp3f5qmx27crf2d2ngwgupc4om4kfq4gyc6vukjom@kyimpnconhdv>
> On Apr 23, 2026, at 01:55, Andres Freund <[email protected]> wrote:
>
> Hi,
>
> On 2026-04-23 00:29:29 +0900, Fujii Masao wrote:
>> On Wed, Apr 22, 2026 at 3:46 PM Chao Li <[email protected]> wrote:
>>>
>>> From my experience, most of the time the postmaster is started with -D. On Linux and macOS, that path can be quite long, PATH_MAX is often 4096 on many Unix-like systems, and I am not sure about Windows. So I think this leak is worth fixing.
>>
>> We can also free()/pfree() userDoption in postgres.c and bootstrap.c?
>>
>> Since userDoption typically uses only a small amount of memory, I'm not sure
>> this patch provides much practical benefit from a memory-leak perspective.
>
> I don't think this is a leak at all. We *never* can reach the end of the scope
> in which userDoption is allocated. We abort() if the end of PostmasterMain()
> is ever reached. What is the leak here supposed to actually be?
>
Yes, calling it “memory leak” is too strict. Usually, memory leak implies repeatedly losing memory over time, but in this case, userDoption is no longer used after feeding to SelectConfigFiles(). So calling it “unnecessary retained memory” might be more accurate.
In theory, it occupies at most PATH_MAX bytes, but in practice it should be much less than that. So, I agree the benefit of fixing is trivial.
>
> ISTM those strdup()s should actually be pstrdup()s? I suspect changing that
> would also silence valgrind.
>
I also had the question when I read the code. But looks like startup phase all uses malloc/strdup etc. C functions, for example SelectConfigFiles() in guc.c also uses malloc/free. I am not sure what is the standard.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Fix memory leak in postmasterMain
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox