Re: libpq: Remove redundant null pointer checks before free()

Peter Eisentraut <peter.eisentraut@enterprisedb.com>

From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>, Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-06-17T19:07:58Z
Lists: pgsql-hackers

Attachments

On 17.06.22 07:11, Tom Lane wrote:
> Having said that, the pattern "if (x) free(x);" is absolutely
> ubiquitous across our code, and so I'm not sure that I'm on
> board with undoing it only in libpq.  I'd be happier if we made
> a push to get rid of it everywhere.

Sure, here is a more comprehensive patch set.  (It still looks like 
libpq is the largest chunk.)

> Notably, I think the choice
> that pfree(NULL) is disallowed traces directly to worries about
> coding-pattern-compatibility with pre-POSIX free().  Should we
> revisit that?

Yes please, and also repalloc().

Commits

  1. Remove redundant null pointer checks before PQclear and PQconninfoFree

  2. Remove redundant null pointer checks before free()

  3. Remove redundant null pointer checks before pg_free()