| From: | Dominique Devienne <ddevienne(at)gmail(dot)com> |
|---|---|
| To: | Igor Korot <ikorot01(at)gmail(dot)com> |
| Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Any reason why PQclear() do not assign the pointer to NULL? |
| Date: | 2026-04-01 07:53:55 |
| Message-ID: | CAFCRh--uw6DBA3Vvz7yh+XFJdi3B6ELF3QiXUwbdKPzKPw2QNQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Gabriel Sánchez | 2026-04-01 14:56:20 | How to query with more workers on a large table with many partitions |
| Previous Message | Matthias Apitz | 2026-04-01 07:32:44 | Re: malformated LSB header in postgres: missing LSB end marker, aborting |