@ -781,13 +781,21 @@ MemoryContextAlloc(MemoryContext context, Size size)
context - > isReset = false ;
context - > isReset = false ;
ret = context - > methods - > alloc ( context , size ) ;
ret = context - > methods - > alloc ( context , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
/*
* Here , and elsewhere in this module , we show the target context ' s
* " name " but not its " ident " ( if any ) in user - visible error messages .
* The " ident " string might contain security - sensitive data , such as
* values in SQL commands .
*/
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
@ -816,13 +824,14 @@ MemoryContextAllocZero(MemoryContext context, Size size)
context - > isReset = false ;
context - > isReset = false ;
ret = context - > methods - > alloc ( context , size ) ;
ret = context - > methods - > alloc ( context , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
@ -853,13 +862,14 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
context - > isReset = false ;
context - > isReset = false ;
ret = context - > methods - > alloc ( context , size ) ;
ret = context - > methods - > alloc ( context , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
@ -888,7 +898,7 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
context - > isReset = false ;
context - > isReset = false ;
ret = context - > methods - > alloc ( context , size ) ;
ret = context - > methods - > alloc ( context , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
if ( ( flags & MCXT_ALLOC_NO_OOM ) = = 0 )
if ( ( flags & MCXT_ALLOC_NO_OOM ) = = 0 )
{
{
@ -896,7 +906,8 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
return NULL ;
return NULL ;
}
}
@ -914,26 +925,28 @@ palloc(Size size)
{
{
/* duplicates MemoryContextAlloc to avoid increased overhead */
/* duplicates MemoryContextAlloc to avoid increased overhead */
void * ret ;
void * ret ;
MemoryContext context = CurrentMemoryContext ;
AssertArg ( MemoryContextIsValid ( CurrentMemoryC ontext) ) ;
AssertArg ( MemoryContextIsValid ( c ontext) ) ;
AssertNotInCriticalSection ( CurrentMemoryC ontext) ;
AssertNotInCriticalSection ( c ontext) ;
if ( ! AllocSizeIsValid ( size ) )
if ( ! AllocSizeIsValid ( size ) )
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
CurrentMemoryC ontext- > isReset = false ;
c ontext- > isReset = false ;
ret = CurrentMemoryC ontext- > methods - > alloc ( CurrentMemoryC ontext, size ) ;
ret = c ontext- > methods - > alloc ( c ontext, size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( CurrentMemoryC ontext, ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( c ontext, ret , size ) ;
return ret ;
return ret ;
}
}
@ -943,26 +956,28 @@ palloc0(Size size)
{
{
/* duplicates MemoryContextAllocZero to avoid increased overhead */
/* duplicates MemoryContextAllocZero to avoid increased overhead */
void * ret ;
void * ret ;
MemoryContext context = CurrentMemoryContext ;
AssertArg ( MemoryContextIsValid ( CurrentMemoryC ontext) ) ;
AssertArg ( MemoryContextIsValid ( c ontext) ) ;
AssertNotInCriticalSection ( CurrentMemoryC ontext) ;
AssertNotInCriticalSection ( c ontext) ;
if ( ! AllocSizeIsValid ( size ) )
if ( ! AllocSizeIsValid ( size ) )
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
CurrentMemoryC ontext- > isReset = false ;
c ontext- > isReset = false ;
ret = CurrentMemoryC ontext- > methods - > alloc ( CurrentMemoryC ontext, size ) ;
ret = c ontext- > methods - > alloc ( c ontext, size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( CurrentMemoryC ontext, ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( c ontext, ret , size ) ;
MemSetAligned ( ret , 0 , size ) ;
MemSetAligned ( ret , 0 , size ) ;
@ -974,18 +989,19 @@ palloc_extended(Size size, int flags)
{
{
/* duplicates MemoryContextAllocExtended to avoid increased overhead */
/* duplicates MemoryContextAllocExtended to avoid increased overhead */
void * ret ;
void * ret ;
MemoryContext context = CurrentMemoryContext ;
AssertArg ( MemoryContextIsValid ( CurrentMemoryC ontext) ) ;
AssertArg ( MemoryContextIsValid ( c ontext) ) ;
AssertNotInCriticalSection ( CurrentMemoryC ontext) ;
AssertNotInCriticalSection ( c ontext) ;
if ( ( ( flags & MCXT_ALLOC_HUGE ) ! = 0 & & ! AllocHugeSizeIsValid ( size ) ) | |
if ( ( ( flags & MCXT_ALLOC_HUGE ) ! = 0 & & ! AllocHugeSizeIsValid ( size ) ) | |
( ( flags & MCXT_ALLOC_HUGE ) = = 0 & & ! AllocSizeIsValid ( size ) ) )
( ( flags & MCXT_ALLOC_HUGE ) = = 0 & & ! AllocSizeIsValid ( size ) ) )
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
elog ( ERROR , " invalid memory alloc request size %zu " , size ) ;
CurrentMemoryC ontext- > isReset = false ;
c ontext- > isReset = false ;
ret = CurrentMemoryC ontext- > methods - > alloc ( CurrentMemoryC ontext, size ) ;
ret = c ontext- > methods - > alloc ( c ontext, size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
if ( ( flags & MCXT_ALLOC_NO_OOM ) = = 0 )
if ( ( flags & MCXT_ALLOC_NO_OOM ) = = 0 )
{
{
@ -993,12 +1009,13 @@ palloc_extended(Size size, int flags)
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
return NULL ;
return NULL ;
}
}
VALGRIND_MEMPOOL_ALLOC ( CurrentMemoryC ontext, ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( c ontext, ret , size ) ;
if ( ( flags & MCXT_ALLOC_ZERO ) ! = 0 )
if ( ( flags & MCXT_ALLOC_ZERO ) ! = 0 )
MemSetAligned ( ret , 0 , size ) ;
MemSetAligned ( ret , 0 , size ) ;
@ -1038,13 +1055,14 @@ repalloc(void *pointer, Size size)
Assert ( ! context - > isReset ) ;
Assert ( ! context - > isReset ) ;
ret = context - > methods - > realloc ( context , pointer , size ) ;
ret = context - > methods - > realloc ( context , pointer , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_CHANGE ( context , pointer , ret , size ) ;
VALGRIND_MEMPOOL_CHANGE ( context , pointer , ret , size ) ;
@ -1072,13 +1090,14 @@ MemoryContextAllocHuge(MemoryContext context, Size size)
context - > isReset = false ;
context - > isReset = false ;
ret = context - > methods - > alloc ( context , size ) ;
ret = context - > methods - > alloc ( context , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
VALGRIND_MEMPOOL_ALLOC ( context , ret , size ) ;
@ -1106,13 +1125,14 @@ repalloc_huge(void *pointer, Size size)
Assert ( ! context - > isReset ) ;
Assert ( ! context - > isReset ) ;
ret = context - > methods - > realloc ( context , pointer , size ) ;
ret = context - > methods - > realloc ( context , pointer , size ) ;
if ( ret = = NULL )
if ( unlikely ( ret = = NULL ) )
{
{
MemoryContextStats ( TopMemoryContext ) ;
MemoryContextStats ( TopMemoryContext ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
( errcode ( ERRCODE_OUT_OF_MEMORY ) ,
errmsg ( " out of memory " ) ,
errmsg ( " out of memory " ) ,
errdetail ( " Failed on request of size %zu. " , size ) ) ) ;
errdetail ( " Failed on request of size %zu in memory context \" %s \" . " ,
size , context - > name ) ) ) ;
}
}
VALGRIND_MEMPOOL_CHANGE ( context , pointer , ret , size ) ;
VALGRIND_MEMPOOL_CHANGE ( context , pointer , ret , size ) ;