Re: BUG #16321: Memory leaks in PostmasterMain

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hghwng(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16321: Memory leaks in PostmasterMain
Date: 2020-03-27 14:52:38
Message-ID: 29212.1585320758@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The argument parsing duplicates strings, but never frees them.

This hardly amounts to enough of a problem to worry about. The
string might be leaked, or it might not, but tracking whether it
is is more trouble than it's worth. Generally we only worry about
memory leaks if they (a) can waste a lot of memory or (b) can
repeat, and thereby accumulate to waste a lot of memory. Surely
neither one applies to postmaster argument parsing.

> For example, when you pass "-D $DATA_DIR" to postmaster, postmaster
> duplicates the string here:
> https://github.com/postgres/postgres/blob/master/src/backend/postmaster/postmaster.c#L698
> The duplicated string is passed to `SelectConfigFiles`, which does
> everything except freeing the string.

This is a great example of a case where the cure is likely to be
worse than the disease. SelectConfigFiles surely has little business
freeing its input string (indeed, it couldn't do so without casting
away the "const"). On the other hand, the caller doesn't really
know whether SelectConfigFiles is going to stash away a copy of the
pointer; it wouldn't be unreasonable for it to do so. So in order
to not perhaps-leak a few dozen bytes, we'd have to make that API
more complicated and more fragile. It's not a win.

As for why we strdup the argument in the first place, see here:

https://www.postgresql.org/message-id/flat/20121008184026.GA28752%40momjian.us

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2020-03-27 15:29:29 BUG #16324: bad cost estimates for generic query plans
Previous Message Tomas Vondra 2020-03-27 14:50:58 Re: BUG #16314: Database Cache Hit Ratio (Warning)