0001-Add-assertion-for-failed-alloc-to-palloc0-and-palloc.patch
text/x-patch
Filename: 0001-Add-assertion-for-failed-alloc-to-palloc0-and-palloc.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0001
Subject: Add assertion for failed alloc to palloc0() and palloc_extended()
| File | + | − |
|---|---|---|
| src/backend/utils/mmgr/mcxt.c | 3 | 1 |
From 7165657a4b62ac35e2c67b9e51035be2a5fbb93f Mon Sep 17 00:00:00 2001
From: Andreas Karlsson <andreas.karlsson@percona.com>
Date: Sat, 1 Mar 2025 00:27:52 +0100
Subject: [PATCH] Add assertion for failed alloc to palloc0() and
palloc_extended()
The palloc() call asserts that the alloc function does not return NULL
so do the same in palloc0(). In palloc_extend() we can assert the same
as long as the MCXT_ALLOC_NO_OOM flag is not set, so let's do so.
---
src/backend/utils/mmgr/mcxt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index aa6da0d0352..ce108788259 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -1356,7 +1356,8 @@ palloc0(Size size)
context->isReset = false;
ret = context->methods->alloc(context, size, 0);
-
+ /* We expect OOM to be handled by the alloc function */
+ Assert(ret != NULL);
VALGRIND_MEMPOOL_ALLOC(context, ret, size);
MemSetAligned(ret, 0, size);
@@ -1379,6 +1380,7 @@ palloc_extended(Size size, int flags)
ret = context->methods->alloc(context, size, flags);
if (unlikely(ret == NULL))
{
+ Assert(flags & MCXT_ALLOC_NO_OOM);
return NULL;
}
--
2.47.2