!3657 修复OptMemoryContext在Debug模式下未正确设置哨兵导致内存检查失败的问题
Merge pull request !3657 from april01xxx/memopt_debug_fix
This commit is contained in:
@ -1603,10 +1603,14 @@ void GenericMemoryAllocator::AllocSetStats(MemoryContext context, int level)
|
||||
void AllocSetCheckPointer(void* pointer)
|
||||
{
|
||||
AllocChunkData* chunk = (AllocChunkData*)(((char*)(pointer)) - ALLOC_CHUNKHDRSZ);
|
||||
AllocMagicData* magic =
|
||||
(AllocMagicData*)(((char*)chunk) + ALLOC_CHUNKHDRSZ + MAXALIGN(chunk->requested_size) - ALLOC_MAGICHDRSZ);
|
||||
|
||||
Assert(magic->aset == chunk->aset && magic->size == chunk->size && magic->posnum == PosmagicNum);
|
||||
/* For opt memory context, we use sentinel instead of magic number to protect memory overflow. */
|
||||
if (!IsOptAllocSetContext(chunk->aset)) {
|
||||
AllocMagicData* magic =
|
||||
(AllocMagicData*)(((char*)chunk) + ALLOC_CHUNKHDRSZ + MAXALIGN(chunk->requested_size) - ALLOC_MAGICHDRSZ);
|
||||
|
||||
Assert(magic->aset == chunk->aset && magic->size == chunk->size && magic->posnum == PosmagicNum);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -864,6 +864,8 @@ static void* opt_AllocSetRealloc(MemoryContext context, void* pointer, Size alig
|
||||
if (oldsize >= size) {
|
||||
#ifdef MEMORY_CONTEXT_CHECKING
|
||||
chunk->requested_size = size;
|
||||
if (size < oldsize)
|
||||
set_sentinel(pointer, size);
|
||||
#endif
|
||||
return pointer;
|
||||
}
|
||||
@ -914,6 +916,8 @@ static void* opt_AllocSetRealloc(MemoryContext context, void* pointer, Size alig
|
||||
chunk->size = chksize;
|
||||
#ifdef MEMORY_CONTEXT_CHECKING
|
||||
chunk->requested_size = size;
|
||||
if (size < chunk->size)
|
||||
set_sentinel(AllocChunkGetPointer(chunk), size);
|
||||
#endif
|
||||
return AllocChunkGetPointer(chunk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user