Re: Add malloc attribute to memory allocation functions - Mailing list pgsql-hackers

From Tristan Partin
Subject Re: Add malloc attribute to memory allocation functions
Date
Msg-id DJRMU1Z9461P.184EDJQZ9DH8D@partin.io
Whole thread
In response to Re: Add malloc attribute to memory allocation functions  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Add malloc attribute to memory allocation functions
List pgsql-hackers
On Mon Jul 6, 2026 at 4:26 AM UTC, Tom Lane wrote:
> "Tristan Partin" <tristan@partin.io> writes:
>> Given that we now have a tree that compiles fine against
>> -Werror=mismatched-dealloc, we need to make sure that we don't regress.
>> By adding the malloc attribute[0], we can protect against regressions,
>> enable more accurate code coverage with -fanalyzer, and allow the
>> compiler to do some optimizations.
>
> I'm skeptical that this is going to lead to anything but grief.
> In particular, since gcc has never heard of memory contexts,
> I don't see how we are not going to get buried in bogus
> -Wanalyzer-malloc-leak warnings.  It doesn't really help
> to add compiler annotations that only sort-of match our semantics.
>
> (This opinion is based on years of dismissing useless Coverity
> warnings of this kind.)

This is a fair criticism. On master, the number of
-Wanalyzer-malloc-leak warnings is 62. With this patch applied, it
balloons to 598.

--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)



pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore
Next
From: Robert Haas
Date:
Subject: Re: PROPERTY GRAPH pg_dump ACL minimization