pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: wliang@stu.xidian.edu.cn, pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: Report a potential memory leak in setup_config()
Date: Tue, 15 Feb 2022 11:33:26 -0500
Message-ID: <3052163.1644942806@sss.pgh.pa.us> (raw)
In-Reply-To: <A7070803-5A15-486E-AE04-ECC13CD10038@yesql.se>
References: <64ee7543.20d.17efb1270ca.Coremail.wliang@stu.xidian.edu.cn>
	<A7070803-5A15-486E-AE04-ECC13CD10038@yesql.se>

Daniel Gustafsson <daniel@yesql.se> writes:
> On 15 Feb 2022, at 02:49, wliang@stu.xidian.edu.cn wrote:
>> Specifically, at line 1095, function pretty_wal_size() is called, which allocates a chunk of memory by using pg_malloc and returns it. However, the return chunk is directly passed to snprintf as its 3rd parameter. As a result, there is a memory leak.

> PostgreSQL isn't all too concerned about small static leaks in short lived
> programs, like initdb.  Memory will be freed shortly when the program exits.
> Complicating the code to save 28 bytes seems hardly worth it, but if you feel
> strongly about it I suggest proposing a patch to fix it.

Yeah.  A quick run of initdb under valgrind reports

==3051337== LEAK SUMMARY:
==3051337==    definitely lost: 893,446 bytes in 47 blocks
==3051337==    indirectly lost: 4,490 bytes in 51 blocks
==3051337==      possibly lost: 0 bytes in 0 blocks
==3051337==    still reachable: 2,403 bytes in 22 blocks
==3051337==         suppressed: 0 bytes in 0 blocks

It might be worth trying to knock that down a bit, but I wouldn't
start with a one-time leak of 28 bytes.  It looks like the biggest
offender is that we don't bother trying to reclaim the lines
malloc'd by readfile() and replace_token().  Fixing that is *maybe*
worth the trouble, but TBH no one has complained about initdb's
memory consumption.

			regards, tom lane





view thread (15+ messages)  latest in thread

Message-ID: <3052163.1644942806@sss.pgh.pa.us>
Permalink:  ../3052163.1644942806@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3052163.1644942806@sss.pgh.pa.us

 · 

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: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, daniel@yesql.se, pgsql-bugs@lists.postgresql.org
  Subject: Re: Report a potential memory leak in setup_config()
  In-Reply-To: <3052163.1644942806@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox