Re: Combinations of pg_strdup/free in pg_dump code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Combinations of pg_strdup/free in pg_dump code
Date: 2016-03-28 14:15:47
Message-ID: 5256.1459174547@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> While reading some code of pg_dump, I noticed that the following
> pattern is heavily present:
> lanname = pg_strdup(stuff)
> free(lanname);

> When pg_strdup or any pg-related allocation routines are called, I
> think that we should use pg_free() and not free(). It does not matter
> much in practice because pg_free() calls actually free() and the
> latter per the POSIX spec should do nothing if the input pointer is
> NULL (some version of SunOS that crash on that actually :p), but we
> really had better be consistent in the calls done. Thoughts?

I do not think this is worth troubling over, really. If there are
places that are relying on free(NULL) to work, it might be worth
ensuring they go through pg_free; but the pattern you show here
is perfectly safe. We have other things to do besides create
code churn for this.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-03-28 14:24:04 Re: Draft release notes for next week's releases
Previous Message Andres Freund 2016-03-28 13:59:37 Re: Move PinBuffer and UnpinBuffer to atomics