Safe memory allocation functions - Mailing list pgsql-hackers

From Michael Paquier
Subject Safe memory allocation functions
Date
Msg-id CAB7nPqTvECYmsu6hWRtASivNtBnTBzzSXFmvbaZ2-4+jHa=sNw@mail.gmail.com
Whole thread Raw
Responses Re: Safe memory allocation functions
Re: Safe memory allocation functions
List pgsql-hackers
Hi all,

For the last couple of weeks it has been mentioned a couple of times
that it would be useful to have a set of palloc APIs able to return
NULL on OOM to allow certain code paths to not ERROR and to take
another route when memory is under pressure. This has been for example
mentioned on the FPW compression thread or here:
http://www.postgresql.org/message-id/CAB7nPqRbewhSbJ_tkAogtpcMrxYJsvKKB9p030d0TpijB4t3YA@mail.gmail.com

Attached is a patch adding the following set of functions for frontend
and backends returning NULL instead of reporting ERROR when allocation
fails:
- palloc_safe
- palloc0_safe
- repalloc_safe
This has simply needed some refactoring in aset.c to set up the new
functions by passing an additional control flag, and I didn't think
that adding a new safe version for AllocSetContextCreate was worth it.
Those APIs are not called anywhere yet, but I could for example write
a small extension for that that could be put in src/test/modules or
publish on github in my plugin repo. Also, I am not sure if this is
material for 9.5, even if the patch is not complicated, but let me
know if you are interested in it and I'll add it to the next CF.
Regards,
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Etsuro Fujita
Date:
Subject: Re: Comment typo in src/backend/executor/execMain.c
Next
From: Tom Lane
Date:
Subject: Re: Safe memory allocation functions