diff --git a/Source/Core/Common/Src/CDUtils.cpp b/Source/Core/Common/Src/CDUtils.cpp index f1d7b9bcd4..8339ea85e1 100644 --- a/Source/Core/Common/Src/CDUtils.cpp +++ b/Source/Core/Common/Src/CDUtils.cpp @@ -139,6 +139,7 @@ char ** cdio_get_devices_win32() { const char *drive_str=is_cdrom_win32(drive_letter); if (drive_str != NULL) { cdio_add_device_list(&drives, drive_str, &num_drives); + delete drive_str; } } cdio_add_device_list(&drives, NULL, &num_drives); diff --git a/Source/Core/Common/Src/LogManager.cpp b/Source/Core/Common/Src/LogManager.cpp index 764f761c05..e613f2763d 100644 --- a/Source/Core/Common/Src/LogManager.cpp +++ b/Source/Core/Common/Src/LogManager.cpp @@ -26,7 +26,8 @@ void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, { va_list args; va_start(args, fmt); - LogManager::GetInstance()->Log(level, type, file, line, fmt, args); + if (LogManager::GetInstance()) + LogManager::GetInstance()->Log(level, type, file, line, fmt, args); va_end(args); } @@ -91,11 +92,14 @@ LogManager::LogManager() { } LogManager::~LogManager() { - delete [] &m_Log; // iffy :P for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) { m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog); m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_consoleLog); } + + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + delete m_Log[i]; + delete m_fileLog; delete m_consoleLog; delete logMutex; @@ -131,6 +135,17 @@ void LogManager::removeListener(LogTypes::LOG_TYPE type, LogListener *listener) logMutex->Leave(); } +void LogManager::Init() +{ + m_logManager = new LogManager(); +} + +void LogManager::Shutdown() +{ + delete m_logManager; + m_logManager = NULL; +} + LogContainer::LogContainer(const char* shortName, const char* fullName, bool enable) : m_enable(enable) { strncpy(m_fullName, fullName, 128); @@ -183,7 +198,8 @@ void FileLogListener::Reload() { FileLogListener::~FileLogListener() { free(m_filename); - fclose(m_logfile); + if (m_logfile) + fclose(m_logfile); } void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) { diff --git a/Source/Core/Common/Src/LogManager.h b/Source/Core/Common/Src/LogManager.h index 07f92640fd..a0aecb583e 100644 --- a/Source/Core/Common/Src/LogManager.h +++ b/Source/Core/Common/Src/LogManager.h @@ -165,14 +165,15 @@ public: } static LogManager* GetInstance() { - if (! m_logManager) - m_logManager = new LogManager(); return m_logManager; } static void SetInstance(LogManager *logManager) { m_logManager = logManager; } + + static void Init(); + static void Shutdown(); }; #endif // _LOGMANAGER_H_ diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index 54477a0f62..5921a7f9e1 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -28,12 +28,19 @@ SConfig SConfig::m_Instance; SConfig::SConfig() { - // Make sure we have log manager - LoadSettings(); - //Make sure we load settings - LoadSettingsHLE(); } +void SConfig::Init() +{ + // Make sure we have log manager + m_Instance.LoadSettings(); + //Make sure we load settings + m_Instance.LoadSettingsHLE(); +} + +void SConfig::Shutdown() +{ +} SConfig::~SConfig() { diff --git a/Source/Core/Core/Src/ConfigManager.h b/Source/Core/Core/Src/ConfigManager.h index 6324180933..d320aeda60 100644 --- a/Source/Core/Core/Src/ConfigManager.h +++ b/Source/Core/Core/Src/ConfigManager.h @@ -105,6 +105,9 @@ struct SConfig // Return the permanent and somewhat globally used instance of this struct static SConfig& GetInstance() {return(m_Instance);} + static void Init(); + static void Shutdown(); + private: // constructor diff --git a/Source/Core/Core/Src/PluginManager.cpp b/Source/Core/Core/Src/PluginManager.cpp index 772ca1ab6a..c6874bde89 100644 --- a/Source/Core/Core/Src/PluginManager.cpp +++ b/Source/Core/Core/Src/PluginManager.cpp @@ -41,11 +41,22 @@ #include "Setup.h" // Create the plugin manager class -CPluginManager CPluginManager::m_Instance; +CPluginManager* CPluginManager::m_Instance; // The Plugin Manager Class // ------------ +void CPluginManager::Init() +{ + m_Instance = new CPluginManager; +} + +void CPluginManager::Shutdown() +{ + delete m_Instance; + m_Instance = NULL; +} + // The plugin manager is some sort of singleton that runs during Dolphin's entire lifespan. CPluginManager::CPluginManager() { diff --git a/Source/Core/Core/Src/PluginManager.h b/Source/Core/Core/Src/PluginManager.h index 60838c8ff8..b0aec88de7 100644 --- a/Source/Core/Core/Src/PluginManager.h +++ b/Source/Core/Core/Src/PluginManager.h @@ -46,7 +46,10 @@ typedef std::vectorCPluginInfos; class CPluginManager { public: - static CPluginManager& GetInstance() {return(m_Instance);} + static CPluginManager& GetInstance() {return(*m_Instance);} + static void Init(); + static void Shutdown(); + Common::PluginVideo *GetVideo(); Common::PluginDSP *GetDSP(); Common::PluginPAD *GetPad(int controller); @@ -68,8 +71,7 @@ public: const CPluginInfos& GetPluginInfos() {return(m_PluginInfos);} PLUGIN_GLOBALS* GetGlobals(); private: - static CPluginManager m_Instance; - bool m_Initialized; + static CPluginManager* m_Instance; CPluginInfos m_PluginInfos; PLUGIN_GLOBALS *m_PluginGlobals; diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp index 7cfef5fc0d..68bd292ee5 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -518,6 +518,8 @@ CFrame::~CFrame() #endif ClosePages(); + + delete m_Mgr; } void CFrame::OnQuit(wxCommandEvent& WXUNUSED (event)) diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index b92f3a6d25..6735489ef6 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -57,7 +57,6 @@ IMPLEMENT_APP(DolphinApp) #endif CFrame* main_frame = NULL; -LogManager *logManager = NULL; #ifdef WIN32 //Has no error handling. @@ -106,7 +105,6 @@ bool DolphinApp::OnInit() wxString padPluginFilename; wxString wiimotePluginFilename; - // Detect CPU info and write it to the cpu_info struct cpu_info.Detect(); @@ -116,6 +114,11 @@ bool DolphinApp::OnInit() _CrtSetDbgFlag(tmpflag); #endif + LogManager::Init(); + EventHandler::Init(); + SConfig::Init(); + CPluginManager::Init(); + // Register message box handler #if ! defined(_WIN32) && defined(HAVE_WX) && HAVE_WX RegisterMsgAlertHandler(&wxMsgAlert); @@ -484,6 +487,16 @@ void DolphinApp::OnEndSession() SConfig::GetInstance().SaveSettings(); } +int DolphinApp::OnExit() +{ + CPluginManager::Shutdown(); + SConfig::Shutdown(); + EventHandler::Shutdown(); + LogManager::Shutdown(); + + return wxApp::OnExit(); +} + // ------------ // Talk to GUI diff --git a/Source/Core/DolphinWX/Src/Main.h b/Source/Core/DolphinWX/Src/Main.h index 674556e0f5..207e2236f3 100644 --- a/Source/Core/DolphinWX/Src/Main.h +++ b/Source/Core/DolphinWX/Src/Main.h @@ -27,6 +27,7 @@ class DolphinApp : public wxApp public: bool OnInit(); void OnEndSession(); + int OnExit(); CFrame* GetCFrame(); }; diff --git a/Source/Core/InputCommon/Src/EventHandler.cpp b/Source/Core/InputCommon/Src/EventHandler.cpp index 81890202db..19dc819baf 100644 --- a/Source/Core/InputCommon/Src/EventHandler.cpp +++ b/Source/Core/InputCommon/Src/EventHandler.cpp @@ -19,13 +19,15 @@ EventHandler::~EventHandler() { EventHandler *EventHandler::GetInstance() { // fprintf(stderr, "handler instance %p\n", m_Instance); - - if (! m_Instance) - m_Instance = new EventHandler(); - return m_Instance; + return m_Instance; } -void EventHandler::Destroy() { +void EventHandler::Init() +{ + m_Instance = new EventHandler(); +} + +void EventHandler::Shutdown() { if (m_Instance) delete m_Instance; // fprintf(stderr, "deleting instance %p\n", m_Instance); diff --git a/Source/Core/InputCommon/Src/EventHandler.h b/Source/Core/InputCommon/Src/EventHandler.h index 688f229340..bde6bbf430 100644 --- a/Source/Core/InputCommon/Src/EventHandler.h +++ b/Source/Core/InputCommon/Src/EventHandler.h @@ -51,7 +51,8 @@ public: bool RemoveEventListener(Keys key); void Update(); static EventHandler *GetInstance(); - static void Destroy(); + static void Init(); + static void Shutdown(); bool addEvent(sf::Event *e); static bool TestEvent (Keys k, sf::Event e); #if defined HAVE_WX && HAVE_WX