Fix NO_OOM handling in MemoryContextAllocAligned
Hi,
This has been in my notes for a while. MemoryContextAllocAligned() calls MemoryContextAllocExtended() and passes “flags" with only MCXT_ALLOC_ZERO removed. When “flags" includes MCXT_ALLOC_NO_OOM, MemoryContextAllocExtended() may return NULL, but MemoryContextAllocAligned() doesn't handle the returned NULL, which may
lead to a crash.
AlignedAllocRealloc() wraps MemoryContextAllocAligned() and handles a NULL return from it, which I think further supports that this is a bug.
I didn't find an in-tree call site that passes MCXT_ALLOC_NO_OOM to MemoryContextAllocAligned() or palloc_aligned(), so this cannot be triggered from current core code. However, a third-party extension could hit the bug.
The attached patch is a quick fix that adds a NULL check.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/