Fix incorrect "return NULL" in BumpAllocLarge().
authorTom Lane <[email protected]>
Sun, 11 May 2025 00:22:39 +0000 (20:22 -0400)
committerTom Lane <[email protected]>
Sun, 11 May 2025 00:22:39 +0000 (20:22 -0400)
This must be "return MemoryContextAllocationFailure(context, size, flags)"
instead.  The effect of this oversight is that if we got a malloc
failure right here, the code would act as though MCXT_ALLOC_NO_OOM
had been specified, whether it was or not.  That would likely lead
to a null-pointer-dereference crash at the unsuspecting call site.

Noted while messing with a patch to improve our Valgrind leak
detection support.  Back-patch to v17 where this code came in.

src/backend/utils/mmgr/bump.c

index 434230fd95b92e210457479b989810bbb39943a1..f7a37d1b3e86c0657aa1dc63bae1f8a6747609e9 100644 (file)
@@ -316,7 +316,7 @@ BumpAllocLarge(MemoryContext context, Size size, int flags)
 
    block = (BumpBlock *) malloc(blksize);
    if (block == NULL)
-       return NULL;
+       return MemoryContextAllocationFailure(context, size, flags);
 
    context->mem_allocated += blksize;