postgres.git / summary / log / commit / refs
commit 40d3f8274499cb1dd349f60f2e5915f907acce6e
Author: Michael Paquier <michael@paquier.xyz>
Date: Tue Mar 04 01:53:10 2025 +0000
First released in: 18.0
Add more assertions in palloc0() and palloc_extended()
palloc() includes an assertion checking that an alloc() implementation
never returns NULL for all MemoryContextMethods.
This commit adds a similar assertion in palloc0(). In palloc_extend(),
a different assertion is added, checking that MCXT_ALLOC_NO_OOM is set
when an alloc() routine returns NULL. These additions can be useful to
catch errors when implementing a new set of MemoryContextMethods
routines.
Author: Andreas Karlsson <andreas@proxel.se>
Discussion: https://postgr.es/m/507e8eba-2035-4a12-a777-98199a66beb8@proxel.se
src/backend/utils/mmgr/mcxt.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index aa6da0d0352..91060de0ab7 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,8 @@ palloc_extended(Size size, int flags)
ret = context->methods->alloc(context, size, flags);
if (unlikely(ret == NULL))
{
+ /* NULL can be returned only when using MCXT_ALLOC_NO_OOM */
+ Assert(flags & MCXT_ALLOC_NO_OOM);
return NULL;
}
[parent: ba57dcfdcda8]