Fixed a few memory leaks. Made Init and Shutdown functions for some core systems.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5064 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
666a33eeed
commit
9254a2ddb5
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -46,7 +46,10 @@ typedef std::vector<CPluginInfo>CPluginInfos;
|
|||
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;
|
||||
|
|
|
@ -518,6 +518,8 @@ CFrame::~CFrame()
|
|||
#endif
|
||||
|
||||
ClosePages();
|
||||
|
||||
delete m_Mgr;
|
||||
}
|
||||
|
||||
void CFrame::OnQuit(wxCommandEvent& WXUNUSED (event))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,7 @@ class DolphinApp : public wxApp
|
|||
public:
|
||||
bool OnInit();
|
||||
void OnEndSession();
|
||||
int OnExit();
|
||||
CFrame* GetCFrame();
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue