diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 887acc4b0..d7fb9147a 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -113,10 +113,20 @@ void cleanupCRCThread() { difftime(time(NULL),elapsed) <= 45;) { //sleep(150); } - if(preCacheThread->canShutdown(true)) { - delete preCacheThread; + if(preCacheThread->canShutdown(false)) { + if(preCacheThread->shutdownAndWait() == true) { + delete preCacheThread; + } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + else { + if(preCacheThread->shutdownAndWait() == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + delete preCacheThread; + + //printf("Stopping broadcast thread [%p] - C\n",broadCastThread); + } + } preCacheThread = NULL; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index aa70dbcf2..fa9ba1888 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -66,6 +66,9 @@ MainMenu::~MainMenu() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); delete state; + state = NULL; + delete oldstate; + oldstate = NULL; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index a0ed0a5f4..f18b145d2 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1868,23 +1868,38 @@ ServerSocket::~ServerSocket() { UPNP_Tools::enabledUPNP = false; } + if(urls.controlURL && urls.ipcondescURL && urls.controlURL_CIF) { + FreeUPNPUrls(&urls); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void ServerSocket::stopBroadCastThread() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("Stopping broadcast thread [%p]\n",broadCastThread); + if(broadCastThread != NULL) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(broadCastThread->canShutdown(true) == true) { + //printf("Stopping broadcast thread [%p] - A\n",broadCastThread); + + if(broadCastThread->canShutdown(false) == true) { + sleep(0); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("Stopping broadcast thread [%p] - B\n",broadCastThread); + + if(broadCastThread->shutdownAndWait() == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(broadCastThread->shutdownAndWait() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete broadCastThread; - } + delete broadCastThread; + + //printf("Stopping broadcast thread [%p] - C\n",broadCastThread); } broadCastThread = NULL; + //printf("Stopping broadcast thread [%p] - D\n",broadCastThread); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -1897,6 +1912,9 @@ void ServerSocket::startBroadCastThread() { stopBroadCastThread(); broadCastThread = new BroadCastSocketThread(); + + //printf("Start broadcast thread [%p]\n",broadCastThread); + broadCastThread->setUniqueID(string(__FILE__) + string("_") + string(__FUNCTION__)); broadCastThread->start(); @@ -2286,10 +2304,12 @@ void UPNP_Tools::NETremRedirects(int ext_port) { // BroadCastSocketThread::BroadCastSocketThread() : BaseThread() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + //printf("new broadcast thread [%p]\n",this); } BroadCastSocketThread::~BroadCastSocketThread() { - + //printf("delete broadcast thread [%p]\n",this); } bool BroadCastSocketThread::canShutdown(bool deleteSelfIfShutdownDelayed) { diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index d7e1a65d9..7cbbb83c9 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -320,7 +320,10 @@ void SystemFlags::Close() { //sleep(150); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(threadLogger->canShutdown(true)) { +// if(threadLogger->canShutdown(false)) { +// Sleep(0); +// } + if(threadLogger->shutdownAndWait() == true) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); delete threadLogger; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);