diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index bfc6e06b616..3ee772b4612 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -1415,6 +1415,13 @@ MemoryContextAllocAligned(MemoryContext context, /* perform the actual allocation */ unaligned = MemoryContextAllocExtended(context, alloc_size, flags); + if (unlikely(unaligned == NULL)) + { + /* NULL can be returned only when using MCXT_ALLOC_NO_OOM */ + Assert(flags & MCXT_ALLOC_NO_OOM); + return NULL; + } + /* set the aligned pointer */ aligned = (void *) TYPEALIGN(alignto, (char *) unaligned + sizeof(MemoryChunk));