Fix missing MCXT_ALLOC_NO_OOM handling in MemoryContextAllocAligned

Fix missing NULL check in MemoryContextAllocAligned().  The underlying
call to MemoryContextAllocExtended() could return NULL when
flags contains MCXT_ALLOC_NO_OOM and the underlying malloc fails.

There are no current callers using MemoryContextAllocAligned() that pass
the MCXT_ALLOC_NO_OOM in core, so no live bug fix in core here. However,
an extension might use this pattern, so we'd better fix.

Fix this so we correctly pass the NULL to the caller rather than trying
to write to a NULL memory address.

This also fixes the same bug in AlignedAllocRealloc(), which is also
unused in core.

Backpatch to v16, where these functions first appeared.

Author: Chao Li <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/03f420c37f898b817d24ee6af55eb5e41ec51655

Modified Files
--------------
src/backend/utils/mmgr/mcxt.c | 7 +++++++
1 file changed, 7 insertions(+)

Reply via email to