Fix NO_OOM handling in MemoryContextAllocAligned

Started by Chao Liabout 2 hours ago1 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

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/

Attachments:

v1-0001-Fix-NO_OOM-handling-in-MemoryContextAllocAligned.patchapplication/octet-stream; name=v1-0001-Fix-NO_OOM-handling-in-MemoryContextAllocAligned.patch; x-unix-mode=0644Download+2-1