From 5b1d21d1a15d9dbe7c9dc3e720993817fbd8a465 Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Sun, 14 Feb 2010 14:06:33 +0000 Subject: [PATCH] =?UTF-8?q?Bunch=20of=20tiny=20memory=20leaks=20fixed=20an?= =?UTF-8?q?d=20cleanup,=20=E3=83=95=E3=82=A6=E3=80=9C=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5056 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/WiiUseSrc/Src/io_osx.m | 5 ++-- Source/Core/Common/Src/CDUtils.cpp | 2 +- Source/Core/Common/Src/Thread.cpp | 9 +++++- Source/Core/DiscIO/Src/FileMonitor.cpp | 14 +++++++++- Source/Core/DiscIO/Src/FileSystemGCWii.cpp | 1 + Source/Core/DolphinWX/Src/ISOProperties.cpp | 31 ++++++++++----------- Source/Plugins/Plugin_DSP_HLE/Src/main.cpp | 4 ++- Source/Plugins/Plugin_GCPad/Src/GCPad.cpp | 22 ++++++++------- Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 4 ++- Source/Plugins/Plugin_Wiimote/Src/main.cpp | 4 ++- 10 files changed, 61 insertions(+), 35 deletions(-) diff --git a/Externals/WiiUseSrc/Src/io_osx.m b/Externals/WiiUseSrc/Src/io_osx.m index f465450a00..ab0fda4b1e 100644 --- a/Externals/WiiUseSrc/Src/io_osx.m +++ b/Externals/WiiUseSrc/Src/io_osx.m @@ -30,7 +30,7 @@ * @file * @brief Handles device I/O for *nix. */ - +#define BLUETOOTH_VERSION_USE_CURRENT #include #include @@ -225,7 +225,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { int found_devices; int found_wiimotes; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; IOBluetoothHostController *bth = [[IOBluetoothHostController alloc] init]; if([bth addressAsString] == nil) @@ -250,6 +250,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND); + [bth release]; [bti release]; [sbt release]; diff --git a/Source/Core/Common/Src/CDUtils.cpp b/Source/Core/Common/Src/CDUtils.cpp index 7c0b797e21..f1d7b9bcd4 100644 --- a/Source/Core/Common/Src/CDUtils.cpp +++ b/Source/Core/Common/Src/CDUtils.cpp @@ -407,7 +407,7 @@ char **cdio_get_devices() { #elif __linux__ return cdio_get_devices_linux(); #else - // todo add somewarning +#warning CDIO not supported on your platform! #endif } diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index 37f52e9ce9..87522a87f6 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -416,7 +416,14 @@ void SleepCurrentThread(int ms) void SetCurrentThreadName(const TCHAR* szThreadName) { - pthread_setspecific(threadname_key, strdup(szThreadName)); + char *name = strdup(szThreadName); + // pthread_setspecific returns 0 on success + // free the string from strdup if fails + // creates a memory leak if it actually doesn't fail + // since we don't delete it once we delete the thread + // we are using a single threadname_key anyway for all threads + if(!pthread_setspecific(threadname_key, strdup(szThreadName))) + free(name); INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName); } diff --git a/Source/Core/DiscIO/Src/FileMonitor.cpp b/Source/Core/DiscIO/Src/FileMonitor.cpp index 906af283c2..854ba8a08d 100644 --- a/Source/Core/DiscIO/Src/FileMonitor.cpp +++ b/Source/Core/DiscIO/Src/FileMonitor.cpp @@ -38,7 +38,7 @@ namespace FileMon { -DiscIO::IVolume *OpenISO; +DiscIO::IVolume *OpenISO = NULL; DiscIO::IFileSystem *pFileSystem = NULL; std::vector GCFiles; std::string ISOFile = "", CurrentFile = ""; @@ -70,6 +70,18 @@ bool ShowSound(std::string FileName) // Read the GC file system void ReadGC(std::string FileName) { + // Should have an actual Shutdown procedure or something + if(OpenISO != NULL) + { + delete OpenISO; + OpenISO = NULL; + } + if(pFileSystem != NULL) + { + delete pFileSystem; + pFileSystem = NULL; + } + // GCFiles' pointers are no longer valid after pFileSystem is cleared GCFiles.clear(); OpenISO = DiscIO::CreateVolumeFromFilename(FileName); if (!OpenISO) return; diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp index 12b5cfc21d..9d8ace70da 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp @@ -37,6 +37,7 @@ CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume) CFileSystemGCWii::~CFileSystemGCWii() { + m_FileInfoVector.clear(); } bool CFileSystemGCWii::IsInitialized() const diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index c4cef4f635..f95dc701a3 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -114,13 +114,17 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW LoadGameConfig(); else { + // Will fail out if GameConfig folder doesn't exist FILE *f = fopen(GameIniFile.c_str(), "w"); - fprintf(f, "# %s - %s\n", OpenISO->GetUniqueID().c_str(), OpenISO->GetName().c_str()); - fprintf(f, "[Core] Values set here will override the main dolphin settings.\n"); - fprintf(f, "[EmuState] The Emulation State. 1 is worst, 5 is best, 0 is not set.\n"); - fprintf(f, "[OnFrame] Add memory patches to be applied every frame here.\n"); - fprintf(f, "[ActionReplay] Add action replay cheats here.\n"); - fclose(f); + if (f) + { + fprintf(f, "# %s - %s\n", OpenISO->GetUniqueID().c_str(), OpenISO->GetName().c_str()); + fprintf(f, "[Core] Values set here will override the main dolphin settings.\n"); + fprintf(f, "[EmuState] The Emulation State. 1 is worst, 5 is best, 0 is not set.\n"); + fprintf(f, "[OnFrame] Add memory patches to be applied every frame here.\n"); + fprintf(f, "[ActionReplay] Add action replay cheats here.\n"); + fclose(f); + } if (GameIni.Load(GameIniFile.c_str())) LoadGameConfig(); else @@ -203,20 +207,13 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW CISOProperties::~CISOProperties() { - if (IsVolumeWiiDisc(OpenISO)) - { - for (std::vector::const_iterator PartIter = WiiDisc.begin(); PartIter != WiiDisc.end(); ++PartIter) - { - delete PartIter->FileSystem; // Remember the FileList is a member of DiscIO::IFileSystem - delete PartIter->Partition; - } - WiiDisc.clear(); - } - else + if (!IsVolumeWiiDisc(OpenISO)) if (!IsVolumeWadFile(OpenISO)) if (pFileSystem) delete pFileSystem; - + // two vector's items are no longer valid after deleting filesystem + WiiDisc.clear(); + GCFiles.clear(); delete OpenGameListItem; delete OpenISO; } diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp index 3b53a101d1..dff9c9e5d5 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp @@ -177,7 +177,8 @@ void DllConfig(HWND _hParent) if (!m_ConfigFrame) { - m_ConfigFrame = new DSPConfigDialogHLE(GetParentedWxWindow(_hParent)); + wxWindow *frame = GetParentedWxWindow(_hParent); + m_ConfigFrame = new DSPConfigDialogHLE(frame); // add backends std::vector backends = AudioCommon::GetSoundBackends(); @@ -192,6 +193,7 @@ void DllConfig(HWND _hParent) m_ConfigFrame->ShowModal(); delete m_ConfigFrame; + delete frame; m_ConfigFrame = 0; } #endif diff --git a/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp b/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp index eae0f50b19..e515a22727 100644 --- a/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp +++ b/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp @@ -169,10 +169,12 @@ void DllConfig(HWND _hParent) #if defined(HAVE_WX) && HAVE_WX if (!m_ConfigFrame) { - m_ConfigFrame = new GCPadConfigDialog(GetParentedWxWindow(_hParent)); + wxWindow *frame = GetParentedWxWindow(_hParent); + m_ConfigFrame = new GCPadConfigDialog(frame); m_ConfigFrame->ShowModal(); m_ConfigFrame->Destroy(); m_ConfigFrame = NULL; + delete frame; } #endif } @@ -617,19 +619,19 @@ bool IsKey(int Key) if (MapKey < 256) { Ret = GetAsyncKeyState(MapKey); // Keyboard (Windows) - } + } else if (MapKey < 0x1100) -#elif defined HAVE_X11 && HAVE_X11 +#elif defined HAVE_X11 && HAVE_X11 if (HaveFocus() && (MapKey < 256 || MapKey > 0xf000)) { - char keys[32]; - KeyCode keyCode; - XQueryKeymap(GCdisplay, keys); - keyCode = XKeysymToKeycode(GCdisplay, MapKey); - Ret = (keys[keyCode/8] & (1 << (keyCode%8))); // Keyboard (Linux) - } + char keys[32]; + KeyCode keyCode; + XQueryKeymap(GCdisplay, keys); + keyCode = XKeysymToKeycode(GCdisplay, MapKey); + Ret = (keys[keyCode/8] & (1 << (keyCode%8))); // Keyboard (Linux) + } else if (MapKey < 0x1100) -#else +#else if (MapKey < 0x1100) #endif { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 3c5417eb30..5bccf7b6f3 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -299,7 +299,8 @@ void DllConfig(HWND _hParent) // Prevent user to show more than 1 config window at same time if (allowConfigShow) { - m_ConfigFrame = new GFXConfigDialogOGL(GetParentedWxWindow(_hParent)); + wxWindow *frame = GetParentedWxWindow(_hParent); + m_ConfigFrame = new GFXConfigDialogOGL(frame); #if defined(_WIN32) Win32AddResolutions(); @@ -314,6 +315,7 @@ void DllConfig(HWND _hParent) allowConfigShow = m_ConfigFrame->ShowModal() == 1 ? true : false; delete m_ConfigFrame; + delete frame; m_ConfigFrame = 0; } #endif diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp index 3e61a28000..67f503966a 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp @@ -183,10 +183,12 @@ void DllConfig(HWND _hParent) #if defined(HAVE_WX) && HAVE_WX if (!m_BasicConfigFrame) { - m_BasicConfigFrame = new WiimoteBasicConfigDialog(GetParentedWxWindow(_hParent)); + wxWindow *frame = GetParentedWxWindow(_hParent); + m_BasicConfigFrame = new WiimoteBasicConfigDialog(frame); m_BasicConfigFrame->ShowModal(); m_BasicConfigFrame->Destroy(); m_BasicConfigFrame = NULL; + delete frame; } #endif }