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_mallocand returns it. However, the return chunk is directly passed to snprintf as its 3rd parameter. As a result,
thereis 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