mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-26 03:39:16 +01:00
engine: common: zone: disallow migrating allocations from one pool to another, as this isn't practically used anywhere
This commit is contained in:
parent
1f4f3d7fda
commit
cd47c6b5b3
@ -246,7 +246,7 @@ void *_Mem_Realloc( poolhandle_t poolptr, void *data, size_t size, qboolean clea
|
||||
if( size <= 0 )
|
||||
return data; // no need to reallocate
|
||||
|
||||
if( !poolptr )
|
||||
if( unlikely( !poolptr ))
|
||||
{
|
||||
Sys_Error( "Mem_Realloc: pool == NULL (alloc at %s:%i)\n", filename, fileline );
|
||||
return NULL;
|
||||
@ -260,6 +260,13 @@ void *_Mem_Realloc( poolhandle_t poolptr, void *data, size_t size, qboolean clea
|
||||
if( !Mem_CheckAllocHeader( "Mem_Realloc", mem, filename, fileline ))
|
||||
return NULL;
|
||||
|
||||
if( unlikely( mem->poolptr != poolptr ))
|
||||
{
|
||||
Sys_Error( "Mem_Realloc: pool migration is not allowed (alloc at %s:%i, realloc at %s:%i)\n",
|
||||
Mem_CheckFilename( mem->filename ), mem->fileline, filename, fileline );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
oldsize = mem->size;
|
||||
if( size == oldsize )
|
||||
return data;
|
||||
@ -289,16 +296,7 @@ void *_Mem_Realloc( poolhandle_t poolptr, void *data, size_t size, qboolean clea
|
||||
}
|
||||
else Mem_PoolSubtract( pool, oldsize - size );
|
||||
|
||||
// if allocation was migrated from one pool to another
|
||||
// (this is possible with original Mem_Realloc func)
|
||||
if( unlikely( mem->poolptr != poolptr ))
|
||||
{
|
||||
mempool_t *oldpool = Mem_FindPool( mem->poolptr );
|
||||
|
||||
Mem_PoolUnlinkAlloc( oldpool, mem );
|
||||
Mem_PoolLinkAlloc( pool, mem );
|
||||
}
|
||||
else if( oldmem != (uintptr_t)mem ) // just relink pointers
|
||||
if( oldmem != (uintptr_t)mem ) // just relink pointers
|
||||
{
|
||||
if( mem->next ) mem->next->prev = mem;
|
||||
if( mem->prev ) mem->prev->next = mem;
|
||||
|
Loading…
Reference in New Issue
Block a user