From beb18d32b9781f5d19b6b043b855345d4692a7e5 Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 28 Feb 2011 23:06:23 +0000 Subject: [PATCH] Fixing implicit memory leaks. --- src/net/common/servermanager.cpp | 7 +++++++ src/pokerth_server.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 78478361..317a5876 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -42,6 +42,13 @@ ServerManager::ServerManager(GuiInterface &gui, ConfigFile &config, AvatarManage ServerManager::~ServerManager() { + size_t remainingHandler = 0; + // Call all pending handlers to clean up. + do { + m_ioService->reset(); + remainingHandler = m_ioService->poll(); + } while (remainingHandler > 0); + m_ioService->reset(); } void diff --git a/src/pokerth_server.cpp b/src/pokerth_server.cpp index 1dd6c945..25cc6422 100644 --- a/src/pokerth_server.cpp +++ b/src/pokerth_server.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #ifdef _MSC_VER @@ -78,7 +77,7 @@ main(int argc, char *argv[]) { ENABLE_LEAK_CHECK(); -// _CrtSetBreakAlloc(4772); + //_CrtSetBreakAlloc(10260); bool readonlyConfig = false; string pidFile; @@ -120,9 +119,9 @@ main(int argc, char *argv[]) readonlyConfig = true; } - auto_ptr myQtToolsInterface(CreateQtToolsWrapper()); + boost::shared_ptr myQtToolsInterface(CreateQtToolsWrapper()); //create defaultconfig - ConfigFile *myConfig = new ConfigFile(argv[0], readonlyConfig); + boost::shared_ptr myConfig(new ConfigFile(argv[0], readonlyConfig)); loghelper_init(myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")), logLevel); // TODO: Hack @@ -156,8 +155,8 @@ main(int argc, char *argv[]) } // Create pseudo Gui Wrapper for the server. - boost::shared_ptr myServerGuiInterface(new ServerGuiWrapper(myConfig, NULL, NULL, NULL)); - boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig)); + boost::shared_ptr myServerGuiInterface(new ServerGuiWrapper(myConfig.get(), NULL, NULL, NULL)); + boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig.get())); if (!session->init()) LOG_ERROR("Missing files - please check your directory settings!"); myServerGuiInterface->setSession(session); @@ -169,6 +168,9 @@ main(int argc, char *argv[]) g_pokerthTerminate = true; } myServerGuiInterface->getSession()->terminateNetworkServer(); + session.reset(); + myServerGuiInterface.reset(); + myConfig.reset(); LOG_MSG("Terminating PokerTH dedicated server." << endl); socket_cleanup();