Add malloc attribute to memory allocation functions

From: "Tristan Partin" <tristan(at)partin(dot)io>
To: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Add malloc attribute to memory allocation functions
Date: 2026-07-01 17:51:25
Message-ID: DJNFBUWD276K.2OPIYJQS75W84@partin.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Let me know if I missed any allocators. Additionally, does it make sense
to add the attribute to the various memory context allocator functions
like AllocSetAlloc(), or only on the higher level functions.

[0]: https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-malloc

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

Attachment Content-Type Size
v1-0001-Add-malloc-attribute-to-memory-allocation-functio.patch text/x-patch 9.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Borodin 2026-07-01 17:55:01 Re: [PATCH v1] Allow excluded tables to remain in the pg_restore data-loading path for directory-format dumps
Previous Message Tom Lane 2026-07-01 17:32:57 Re: Macro redefinition warning after aeb07c55fab5c17a600b77ffcdc3b71425d6a8e7