Re: Add malloc attribute to memory allocation functions

Tristan Partin <tristan@partin.io>

From: "Tristan Partin" <tristan@partin.io>
To: "Tom Lane" <tgl@sss.pgh.pa.us>, "Michael Paquier" <michael@paquier.xyz>
Cc: "Peter Eisentraut" <peter@eisentraut.org>, "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2026-07-07T23:57:23Z
Lists: pgsql-hackers
On Tue Jul 7, 2026 at 6:54 PM CDT, Tom Lane wrote:
> Michael Paquier <michael@paquier.xyz> writes:
>> Additional question.  Does this help with requirements like the one
>> listed in fe-exec.c for PQfreemem() under WIN32?
>
> Yeah, I was wondering about that point too.  It would be really nice
> to have automated checks for that.  Maybe the right thing to do here
> (to start anyway) is to put in targeted annotations that address
> specific pain points like that one.
>
> One issue that'd have to be dealt with is that that would involve
> putting annotations into the public header file libpq-fe.h.  We'd need
> to be sure we do not break things for applications using compilers
> other than what we built libpq with.  That seems reasonably easy to do
> with some macro trickery, but it's a point to keep in mind.

Ok, I think the path forward is two-fold:

1. Add the annotations to specific pain points as Tom suggested 
   (PGfreemem(), frontend memory allocators)
2. Add the annotations to the backend allocators knowing that the patch 
   may not be committed

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