From f198d550bc93256fea8301f11455a72b87c06d0d Mon Sep 17 00:00:00 2001
From: "fires.gc" <fires.gc@gmail.com>
Date: Wed, 17 Sep 2008 08:40:52 +0000
Subject: [PATCH] fix for small memory leaks

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@562 8ced0084-cf51-0410-be5f-012b33b47a6e
---
 Source/Core/Common/Src/MemoryUtil.cpp                 | 6 +++++-
 Source/Core/DolphinWX/Src/FileSearch.cpp              | 2 ++
 Source/Plugins/Plugin_VideoDX9/Src/OpcodeDecoding.cpp | 2 +-
 Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp   | 7 +++++--
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/Source/Core/Common/Src/MemoryUtil.cpp b/Source/Core/Common/Src/MemoryUtil.cpp
index 23f8457dec..0099158872 100644
--- a/Source/Core/Common/Src/MemoryUtil.cpp
+++ b/Source/Core/Common/Src/MemoryUtil.cpp
@@ -102,7 +102,11 @@ void* AllocateMemoryPages(int size)
 void FreeMemoryPages(void* ptr, int size)
 {
 #ifdef _WIN32
-	VirtualFree(ptr, 0, MEM_RELEASE);
+	if (ptr)
+	{
+		VirtualFree(ptr, 0, MEM_RELEASE);
+		ptr = NULL;
+	}
 #else
 	munmap(ptr, size);
 #endif
diff --git a/Source/Core/DolphinWX/Src/FileSearch.cpp b/Source/Core/DolphinWX/Src/FileSearch.cpp
index 2e1448bdb5..7ea9974235 100644
--- a/Source/Core/DolphinWX/Src/FileSearch.cpp
+++ b/Source/Core/DolphinWX/Src/FileSearch.cpp
@@ -65,6 +65,8 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string&
 			bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
 		}
 	}
+	FindClose(FindFirst);
+
 
 #else
 	size_t dot_pos = _searchString.rfind(".");
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/OpcodeDecoding.cpp b/Source/Plugins/Plugin_VideoDX9/Src/OpcodeDecoding.cpp
index 9aa7dbf11c..f1e69de2f0 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/OpcodeDecoding.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/OpcodeDecoding.cpp
@@ -373,7 +373,7 @@ void OpcodeDecoder_Init()
 
 void OpcodeDecoder_Shutdown()
 {
-	//VirtualFree((LPVOID)buffer,CMDBUFFER_SIZE,MEM_RELEASE);
+	//VirtualFree((LPVOID)buffer,0,MEM_RELEASE);
 	tempvarray.Destroy();
 }
 
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
index addd1eb92d..d21b7e0a8f 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
@@ -68,8 +68,11 @@ void TextureCache::Shutdown()
 {
 	Invalidate();
 
-	VirtualFree(temp, 0, MEM_RELEASE);	
-	temp = NULL;
+	if (temp != NULL)
+	{
+		VirtualFree(temp, 0, MEM_RELEASE);	
+		temp = NULL;
+	}
 }
 
 void TextureCache::Cleanup()