Skip to content

Commit 58016e8

Browse files
authored
Merge pull request #497 from GeneralsOnlineDevelopmentTeam/seer/bugfix/game-memory-safety
bugfix(memory): Improve GameMemory null safety and logic
2 parents 809242d + 17da294 commit 58016e8

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ BlockCheckpointInfo *Checkpointable::debugAddCheckpointInfo(
14511451
{
14521452
#ifdef MEMORYPOOL_STACKTRACE
14531453
void **stacktrace = bi->getStacktraceInfo();
1454-
if (theStackTraceDepth > 0 && !TheGlobalData || TheGlobalData->m_checkForLeaks)
1454+
if (theStackTraceDepth > 0 && (!TheGlobalData || TheGlobalData->m_checkForLeaks))
14551455
{
14561456
memset(stacktrace, 0, MEMORYPOOL_STACKTRACE_SIZE_BYTES);
14571457
::FillStackAddresses(stacktrace, min(MEMORYPOOL_STACKTRACE_SIZE, theStackTraceDepth), MEMORYPOOL_STACKTRACE_SKIP_SIZE);
@@ -1584,7 +1584,8 @@ MemoryPoolBlob* MemoryPool::createBlob(Int allocationCount)
15841584
blob->addBlobToList(&m_firstBlob, &m_lastBlob);
15851585

15861586
DEBUG_ASSERTCRASH(m_firstBlobWithFreeBlocks == NULL, ("DO NOT IGNORE. Please call John McD - x36872 (m_firstBlobWithFreeBlocks != NULL)"));
1587-
m_firstBlobWithFreeBlocks = blob;
1587+
if (m_firstBlobWithFreeBlocks == NULL)
1588+
m_firstBlobWithFreeBlocks = blob;
15881589

15891590
// bookkeeping
15901591
m_totalBlocksInPool += allocationCount;

GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ BlockCheckpointInfo *Checkpointable::debugAddCheckpointInfo(
14321432
{
14331433
#ifdef MEMORYPOOL_STACKTRACE
14341434
void **stacktrace = bi->getStacktraceInfo();
1435-
if (theStackTraceDepth > 0 && !TheGlobalData || TheGlobalData->m_checkForLeaks)
1435+
if (theStackTraceDepth > 0 && (!TheGlobalData || TheGlobalData->m_checkForLeaks))
14361436
{
14371437
memset(stacktrace, 0, MEMORYPOOL_STACKTRACE_SIZE_BYTES);
14381438
::FillStackAddresses(stacktrace, min(MEMORYPOOL_STACKTRACE_SIZE, theStackTraceDepth), MEMORYPOOL_STACKTRACE_SKIP_SIZE);
@@ -1565,7 +1565,8 @@ MemoryPoolBlob* MemoryPool::createBlob(Int allocationCount)
15651565
blob->addBlobToList(&m_firstBlob, &m_lastBlob);
15661566

15671567
DEBUG_ASSERTCRASH(m_firstBlobWithFreeBlocks == nullptr, ("DO NOT IGNORE. Please call John McD - x36872 (m_firstBlobWithFreeBlocks != nullptr)"));
1568-
m_firstBlobWithFreeBlocks = blob;
1568+
if (m_firstBlobWithFreeBlocks == nullptr)
1569+
m_firstBlobWithFreeBlocks = blob;
15691570

15701571
// bookkeeping
15711572
m_totalBlocksInPool += allocationCount;

0 commit comments

Comments
 (0)