Re: DEREF_AFTER_NULL: src/common/jsonapi.c:2529

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>, Andres Freund <andres(at)anarazel(dot)de>
Cc: Andreas Karlsson <andreas(at)proxel(dot)se>, Галкин Сергей <galkin(at)rutoken(dot)ru>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: DEREF_AFTER_NULL: src/common/jsonapi.c:2529
Date: 2026-04-08 21:25:02
Message-ID: b389c5e5-e4af-45c2-bd51-59dcd358e1e4@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07.04.26 00:01, Jacob Champion wrote:
>>> Or else make pfree() behave like free() [2] so that we don't
>>> have to have that particular papercut at all anymore?
>>
>> -many
>>
>> It's also not a path I want to add any unnecessary instructions to.
>
> Okay, but I'd be curious to know how widespread this position is.

This was recently (as in: I still remember it) discussed:

https://www.postgresql.org/message-id/flat/cf26e970-8e92-59f1-247a-aa265235075b%40enterprisedb.com

Probably not worth opening up again.

But it seems to me that the pfree() in fe_memutils.c should
Assert(pointer != NULL), to be consistent with the backend version.

I've also been thinking sometimes about a pfree_if_nonnull() (which
would do { if (ptr) pfree(ptr)) }. That would in some cases make the
notation more compact and robust. Maybe it could help here too?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2026-04-08 21:30:21 Re: s/pg_attribute_always_inline/pg_always_inline/?
Previous Message Nathan Bossart 2026-04-08 21:23:45 Re: Add pg_stat_autovacuum_priority