From 250564132620c7c0d2a1d51b2be382bf2c71cbdc Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Fri, 16 May 2025 16:54:44 +0200 Subject: [PATCH 1/2] Explicitly check 'this' pointer (GEN). --- Generals/Code/GameEngine/Include/Common/GameMemory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Generals/Code/GameEngine/Include/Common/GameMemory.h b/Generals/Code/GameEngine/Include/Common/GameMemory.h index 03dd4d109a9..bef6f4208ba 100644 --- a/Generals/Code/GameEngine/Include/Common/GameMemory.h +++ b/Generals/Code/GameEngine/Include/Common/GameMemory.h @@ -758,7 +758,8 @@ class MemoryPoolObject void deleteInstance() { - if (this) + void * volatile checkThisPtr = this; // mitigate undefined behavior because this function is called on nullptrs + if (checkThisPtr) { MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl this->~MemoryPoolObject(); // it's virtual, so the right one will be called. From 68151e0740f2a18a2462814ee6c7944af8b84e23 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Fri, 16 May 2025 16:54:54 +0200 Subject: [PATCH 2/2] Explicitly check 'this' pointer (ZH). --- GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h b/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h index 95c5ff12d0e..66fa0b59085 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h @@ -757,7 +757,8 @@ class MemoryPoolObject void deleteInstance() { - if (this) + void * volatile checkThisPtr = this; // mitigate undefined behavior because this function is called on nullptrs + if (checkThisPtr) { MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl this->~MemoryPoolObject(); // it's virtual, so the right one will be called.