Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40d3f82

Browse files
committed
Add more assertions in palloc0() and palloc_extended()
palloc() includes an assertion checking that an alloc() implementationnever 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 setwhen an alloc() routine returns NULL. These additions can be useful tocatch errors when implementing a new set of MemoryContextMethodsroutines.Author: Andreas Karlsson <andreas@proxel.se>Discussion:https://postgr.es/m/507e8eba-2035-4a12-a777-98199a66beb8@proxel.se
1 parentba57dcf commit40d3f82

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎src/backend/utils/mmgr/mcxt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,8 @@ palloc0(Size size)
13561356
context->isReset= false;
13571357

13581358
ret=context->methods->alloc(context,size,0);
1359-
1359+
/* We expect OOM to be handled by the alloc function */
1360+
Assert(ret!=NULL);
13601361
VALGRIND_MEMPOOL_ALLOC(context,ret,size);
13611362

13621363
MemSetAligned(ret,0,size);
@@ -1379,6 +1380,8 @@ palloc_extended(Size size, int flags)
13791380
ret=context->methods->alloc(context,size,flags);
13801381
if (unlikely(ret==NULL))
13811382
{
1383+
/* NULL can be returned only when using MCXT_ALLOC_NO_OOM */
1384+
Assert(flags&MCXT_ALLOC_NO_OOM);
13821385
returnNULL;
13831386
}
13841387

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp