From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: libpq: Remove redundant null pointer checks before free()
Date: Sun, 19 Jun 2022 11:55:33 +0200
Message-ID: <20220619095533.7u35bbei3a2sswdm@alvherre.pgsql> (raw)
In-Reply-To: <5eb1b215-acc2-9922-50d8-fc57a3e4f5e8@enterprisedb.com>
On 2022-Jun-17, Peter Eisentraut wrote:
> From 355ef1a68be690d9bb8ee0524226abd648733ce0 Mon Sep 17 00:00:00 2001
> From: Peter Eisentraut <peter@eisentraut.org>
> Date: Fri, 17 Jun 2022 12:09:32 +0200
> Subject: [PATCH v2 3/3] Remove redundant null pointer checks before PQclear
> and PQconninfofree
>
> These functions already had the free()-like behavior of handling NULL
> pointers as a no-op. But it wasn't documented, so add it explicitly
> to the documentation, too.
For PQclear() specifically, one thing that I thought a few days ago
would be useful would to have it return (PGresult *) NULL. Then the
very common pattern of doing "PQclear(res); res = NULL;" could be
simplified to "res = PQclear(res);", which is nicely compact and is
learned instantly.
I've not seen this convention used anywhere else though, and I'm not
sure I'd advocate it for other functions where we use similar patterns
such as pfree/pg_free, so perhaps it'd become too much of a special
case.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: alvherre@alvh.no-ip.org, peter.eisentraut@enterprisedb.com, tgl@sss.pgh.pa.us, michael@paquier.xyz
Subject: Re: libpq: Remove redundant null pointer checks before free()
In-Reply-To: <20220619095533.7u35bbei3a2sswdm@alvherre.pgsql>
References: <5eb1b215-acc2-9922-50d8-fc57a3e4f5e8@enterprisedb.com> <20220619095533.7u35bbei3a2sswdm@alvherre.pgsql>
* 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