pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: hghwng@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16321: Memory leaks in PostmasterMain
Date: Fri, 27 Mar 2020 10:52:38 -0400
Message-ID: <29212.1585320758@sss.pgh.pa.us> (raw)
In-Reply-To: <16321-c12957af6e8c231c@postgresql.org>
References: <16321-c12957af6e8c231c@postgresql.org>

PG Bug reporting form <noreply@postgresql.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





view thread (4+ messages)  latest in thread

Message-ID: <29212.1585320758@sss.pgh.pa.us>
Permalink:  ../29212.1585320758@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29212.1585320758@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, hghwng@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16321: Memory leaks in PostmasterMain
  In-Reply-To: <29212.1585320758@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