From 704935c53498a95ebc07754de784a471bff6c4cf Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 8 Mar 2013 05:24:37 +0000 Subject: [PATCH] - attempt to fix double free bug reported by tomreyn --- source/glest_game/network/client_interface.cpp | 10 +++++----- source/glest_game/network/network_interface.h | 1 + source/shared_lib/include/platform/sdl/thread.h | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 746ed137..a066da94 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -78,8 +78,7 @@ ClientInterface::ClientInterface() : GameNetworkInterface() { } void ClientInterface::shutdownNetworkCommandListThread() { - //MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE); - + MutexSafeWrapper safeMutex(networkCommandListThreadAccessor,CODE_AT_LINE); if(networkCommandListThread != NULL) { time_t elapsed = time(NULL); this->quit = true; @@ -94,6 +93,10 @@ void ClientInterface::shutdownNetworkCommandListThread() { networkCommandListThread = NULL; } } + + Mutex *tempMutexPtr = networkCommandListThreadAccessor; + networkCommandListThreadAccessor = NULL; + safeMutex.ReleaseLock(false,true); } ClientInterface::~ClientInterface() { @@ -122,9 +125,6 @@ ClientInterface::~ClientInterface() { delete clientSocket; clientSocket = NULL; - delete networkCommandListThreadAccessor; - networkCommandListThreadAccessor = NULL; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index 4410a07a..9a7b1c95 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -281,6 +281,7 @@ protected: public: GameNetworkInterface(); + virtual ~GameNetworkInterface(){} //message processimg virtual void update()= 0; diff --git a/source/shared_lib/include/platform/sdl/thread.h b/source/shared_lib/include/platform/sdl/thread.h index 0a0714ac..a400397f 100644 --- a/source/shared_lib/include/platform/sdl/thread.h +++ b/source/shared_lib/include/platform/sdl/thread.h @@ -162,7 +162,7 @@ public: #endif } } - void ReleaseLock(bool keepMutex=false) { + void ReleaseLock(bool keepMutex=false,bool deleteMutexOnRelease=false) { if(this->mutex != NULL) { #ifdef DEBUG_MUTEXES if(ownerId != "") { @@ -182,6 +182,11 @@ public: } #endif + if(deleteMutexOnRelease == true) { + delete this->mutex; + this->mutex = NULL; + } + if(keepMutex == false) { this->mutex = NULL; }