public inbox for [email protected]  
help / color / mirror / Atom feed
From: Dominique Devienne <[email protected]>
To: Igor Korot <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: Any reason why PQclear() do not assign the pointer to NULL?
Date: Wed, 1 Apr 2026 09:53:55 +0200
Message-ID: <CAFCRh--uw6DBA3Vvz7yh+XFJdi3B6ELF3QiXUwbdKPzKPw2QNQ@mail.gmail.com> (raw)
In-Reply-To: <CA+FnnTzJF=ebHMQQ7gw1X3Ax+99gnWbCQ00Sw0wTgGYTOyXeMQ@mail.gmail.com>
References: <CA+FnnTzJF=ebHMQQ7gw1X3Ax+99gnWbCQ00Sw0wTgGYTOyXeMQ@mail.gmail.com>

Well yes, the fact you're asking is surprising.

void PQclear(PGresult* res);

How could it? C/C++ is pass by value. So PQclear gets a copy of the pointer.
Even if it assigns it internal to nullptr, the calling code has its
own unchanged copy.

It's the same reason free() doesn't either.
It's your responsability to assign nullptr after the PQclear.

In/out argument in general violate the Principle of Least Surprise,
and are best avoided.
You have no way to know reading the code the call has a side effect on
the var (as opposed to the value). FWIW. --DD






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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Any reason why PQclear() do not assign the pointer to NULL?
  In-Reply-To: <CAFCRh--uw6DBA3Vvz7yh+XFJdi3B6ELF3QiXUwbdKPzKPw2QNQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox