Re: Any reason why PQclear() do not assign the pointer to NULL? - Mailing list pgsql-general

From Dominique Devienne
Subject Re: Any reason why PQclear() do not assign the pointer to NULL?
Date
Msg-id CAFCRh--uw6DBA3Vvz7yh+XFJdi3B6ELF3QiXUwbdKPzKPw2QNQ@mail.gmail.com
Whole thread Raw
In response to Any reason why PQclear() do not assign the pointer to NULL?  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Matthias Apitz
Date:
Subject: Re: malformated LSB header in postgres: missing LSB end marker, aborting
Next
From: Gabriel Sánchez
Date:
Subject: How to query with more workers on a large table with many partitions