Forráskód Böngészése

添加WxAdoInterface VS2008工程。数据库连接池存在内存泄漏。

Jeff 6 éve
szülő
commit
5349d405e2

+ 6 - 0
source/hook/WeChats.sln

@@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WeChats", "WeChats\WeChats.
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WxService", "WxService\WxService.vcproj", "{F6D9B47B-95FF-4A7D-BA72-F33A0506BE21}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WxAdoInterface", "WxAdoInterface\WxAdoInterface.vcproj", "{C9691ACA-CDE0-4709-A295-533DFB148A37}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
@@ -25,6 +27,10 @@ Global
 		{F6D9B47B-95FF-4A7D-BA72-F33A0506BE21}.Debug|Win32.Build.0 = Debug|Win32
 		{F6D9B47B-95FF-4A7D-BA72-F33A0506BE21}.Release|Win32.ActiveCfg = Release|Win32
 		{F6D9B47B-95FF-4A7D-BA72-F33A0506BE21}.Release|Win32.Build.0 = Release|Win32
+		{C9691ACA-CDE0-4709-A295-533DFB148A37}.Debug|Win32.ActiveCfg = Debug|Win32
+		{C9691ACA-CDE0-4709-A295-533DFB148A37}.Debug|Win32.Build.0 = Debug|Win32
+		{C9691ACA-CDE0-4709-A295-533DFB148A37}.Release|Win32.ActiveCfg = Release|Win32
+		{C9691ACA-CDE0-4709-A295-533DFB148A37}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 2
source/hook/WeChats/WeChats.vcproj

@@ -22,7 +22,7 @@
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
 			ConfigurationType="1"
 			UseOfMFC="2"
-			CharacterSet="1"
+			CharacterSet="2"
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
@@ -101,7 +101,7 @@
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
 			ConfigurationType="1"
 			UseOfMFC="2"
-			CharacterSet="1"
+			CharacterSet="2"
 			WholeProgramOptimization="1"
 			>
 			<Tool

+ 3 - 0
source/hook/WxAdoInterface/Global.cpp

@@ -2,6 +2,9 @@
 #include "Global.h"
 #include "CritSection.h"
 #include <locale.h>
+// PathFileExistsÍ·Îļþ;
+#include <shlwapi.h>
+#pragma comment(lib,"shlwapi.lib")
 
 namespace Global
 {

+ 5 - 5
source/hook/WxAdoInterface/Resource.h

@@ -1,16 +1,16 @@
 //{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
-// 供 WxAdoInterface.rc 使用
+// Used by WxAdoInterface.rc
 //
 
-// 新对象的下一组默认值
+// �¶������һ��Ĭ��ֵ
 //
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 
-#define _APS_NEXT_RESOURCE_VALUE	1000
-#define _APS_NEXT_CONTROL_VALUE		1000
-#define _APS_NEXT_SYMED_VALUE		1000
+#define _APS_NEXT_RESOURCE_VALUE	7000
+#define _APS_NEXT_CONTROL_VALUE		7000
+#define _APS_NEXT_SYMED_VALUE		7000
 #define _APS_NEXT_COMMAND_VALUE		32771
 #endif
 #endif

+ 0 - 1
source/hook/WxAdoInterface/WxAdoInterface.cpp

@@ -75,7 +75,6 @@ extern "C" IWxAdoInterface* PASCAL EXPORT CreateWxAdoPoolInstance()
  		pInstance->AddRef();
  
  	return pInstance;
-	return NULL;
 }
 
 int CWxAdoInterfaceApp::ExitInstance()

BIN
source/hook/WxAdoInterface/WxAdoInterface.rc


+ 297 - 0
source/hook/WxAdoInterface/WxAdoInterface.vcproj

@@ -0,0 +1,297 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="WxAdoInterface"
+	ProjectGUID="{C9691ACA-CDE0-4709-A295-533DFB148A37}"
+	RootNamespace="WxAdoInterface"
+	Keyword="MFCDLLProj"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
+			ConfigurationType="2"
+			UseOfMFC="2"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="_DEBUG"
+				MkTypLibCompatible="false"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL;_AFXEXT"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="2"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="2052"
+				AdditionalIncludeDirectories="$(IntDir)"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="2"
+				ModuleDefinitionFile=".\WxAdoInterface.def"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine="xcopy $(TargetDir)$(ProjectName).lib $(SolutionDir)WxService\ /Y /A"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
+			ConfigurationType="2"
+			UseOfMFC="2"
+			CharacterSet="2"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="NDEBUG"
+				MkTypLibCompatible="false"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL;_AFXEXT"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="2052"
+				AdditionalIncludeDirectories="$(IntDir)"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="1"
+				ModuleDefinitionFile=".\WxAdoInterface.def"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine="xcopy $(TargetDir)$(ProjectName).lib $(SolutionDir)WxService\ /Y /A"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Ô´Îļþ"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\Global.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\stdafx.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\WxAdoImpl.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoInterface.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoInterface.def"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoPool.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Í·Îļþ"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\CritSection.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Global.h"
+				>
+			</File>
+			<File
+				RelativePath=".\IWxAdoInterface.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Resource.h"
+				>
+			</File>
+			<File
+				RelativePath=".\SafeList.h"
+				>
+			</File>
+			<File
+				RelativePath=".\stdafx.h"
+				>
+			</File>
+			<File
+				RelativePath=".\targetver.h"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoImpl.h"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoInterface.h"
+				>
+			</File>
+			<File
+				RelativePath=".\WxAdoPool.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="×ÊÔ´Îļþ"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+			<File
+				RelativePath=".\WxAdoInterface.rc"
+				>
+			</File>
+			<File
+				RelativePath=".\res\WxAdoInterface.rc2"
+				>
+			</File>
+		</Filter>
+		<File
+			RelativePath=".\ReadMe.txt"
+			>
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

+ 19 - 3
source/hook/WxAdoInterface/WxAdoPool.cpp

@@ -94,13 +94,29 @@ void CWxAdoPool::DestroyAllDBConnections()
 		Sleep(1000);
 	}
 	
+	pAdoObj pObj = NULL;
 	AdoConnList::iterator itIdle = m_listIdleConnections.begin();
 	while (itIdle != m_listIdleConnections.end())
 	{
-		if (NULL != (*itIdle))
+		pObj = *itIdle;
+		if (NULL != pObj)
 		{
-			(*itIdle)->pConnection->Close();
-			delete (*itIdle);
+ 			//if (pObj->pConnection)
+ 			//{
+ 			//	pObj->pConnection->Close();
+ 			//	pObj->pConnection->Release();
+ 			//}
+ 
+ 			//if (pObj->pCommand)
+ 			//{
+ 			//	pObj->pCommand->Release();
+ 			//}
+ 
+ 			//if (pObj->pRecordSet)
+ 			//	pObj->pRecordSet.Release();
+
+			delete pObj;
+			pObj = NULL;
 		}
 		itIdle = m_listIdleConnections.erase(itIdle);
 	}

BIN
source/hook/WxAdoInterface/res/WxAdoInterface.rc2


+ 20 - 0
source/hook/WxAdoInterface/stdafx.h

@@ -48,4 +48,24 @@ typedef struct __ADO__
 	_ConnectionPtr pConnection;
 	_RecordsetPtr pRecordSet;
 	_CommandPtr pCommand;
+	//~__ADO__()
+	//{
+	//	if (pCommand)
+	//	{
+	//		//pCommand->Close();
+	//		pCommand->Release();
+	//	}
+
+	//	if (pRecordSet)
+	//	{
+	//		pRecordSet->Close();
+	//		pRecordSet->Release();
+	//	}
+
+	//	if (pConnection)
+	//	{
+	//		pConnection->Close();
+	//		pConnection->Release();
+	//	}
+	//}
 }AdoObj, *pAdoObj;

+ 3 - 0
source/hook/WxService/Global.cpp

@@ -462,7 +462,10 @@ namespace Global
 
 			pe32.dwSize = sizeof(PROCESSENTRY32);
 			if ( !Process32First(hProcessSnap, &pe32) )
+			{
+				CloseHandle(hProcessSnap);
 				return 0;
+			}
 
 			do
 			{

+ 27 - 4
source/hook/WxService/MainProcess.cpp

@@ -19,14 +19,14 @@ void CMainProcess::StartWork()
 	m_hEvent1 = CreateEvent(NULL, TRUE, FALSE, NULL);
 	if ( m_hEvent1 == NULL )
 	{
-		_tprintf_s(_T("创建事件失败\n"));
+		//_tprintf_s(_T("创建事件失败\n"));
 		return;
 	}
 
 	m_hEvent2 = CreateEvent(NULL, TRUE, FALSE, NULL);
 	if ( m_hEvent2 == NULL )
 	{
-		_tprintf_s(_T("创建事件失败2\n"));
+		//_tprintf_s(_T("创建事件失败2\n"));
 		return;
 	}
 
@@ -39,7 +39,7 @@ void CMainProcess::StartWork()
 		CloseHandle(m_hEvent2);
 		m_hEvent1 = NULL;
 		m_hEvent2 = NULL;
-		_tprintf_s(_T("创建线程失败\n"));
+		//_tprintf_s(_T("创建线程失败\n"));
 		return;
 	}
 
@@ -56,14 +56,37 @@ void CMainProcess::StartWork()
 		if (m_hBackupDatabase)
 			CloseHandle(m_hBackupDatabase);
 		m_hBackupDatabase = NULL;
-		_tprintf_s(_T("创建线程失败2\n"));
+		//_tprintf_s(_T("创建线程失败2\n"));
 		return;
 	}
 }
 
 void CMainProcess::EndofWork()
 {
+	if ( m_hEvent1 )
+	{
+		SetEvent(m_hEvent1);
+		CloseHandle(m_hEvent1);
+	}
+
+	if ( m_hEvent2 )
+	{
+		SetEvent(m_hEvent2);
+		CloseHandle(m_hEvent2);
+	}
+
+
+	if ( m_hCheckServices )
+	{
+		WaitForSingleObject(m_hCheckServices,INFINITE);
+		CloseHandle(m_hCheckServices);
+	}
 
+	if ( m_hBackupDatabase )
+	{
+		WaitForSingleObject(m_hBackupDatabase,INFINITE);
+		CloseHandle(m_hBackupDatabase);
+	}
 }
 
 DWORD CMainProcess::CheckSvcStatusThread(LPVOID lpVoid)

+ 8 - 2
source/hook/WxService/WxService.cpp

@@ -35,7 +35,6 @@ void CALLBACK WorkStart()
 	}
 
 	
-
 	WinService::GetDebugPriv();
 	CMainProcess::GetInstance()->StartWork();
 }
@@ -43,7 +42,14 @@ void CALLBACK WorkStart()
 // š¤×÷˝áĘřťŘľ÷şŻĘý;
 void CALLBACK WorkEndof()
 {
-	CMainProcess::GetInstance()->EndofWork();
+	FreelyfzodbcLibrary();
+	CMainProcess *pObj = CMainProcess::GetInstance();
+	if (pObj)
+	{	
+		pObj->EndofWork();
+		delete pObj;
+		pObj = NULL;
+	}
 }
 
 

+ 2 - 2
source/hook/WxService/WxService.vcproj

@@ -22,7 +22,7 @@
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
 			ConfigurationType="1"
 			UseOfMFC="2"
-			CharacterSet="1"
+			CharacterSet="2"
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
@@ -94,7 +94,7 @@
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)\"
 			ConfigurationType="1"
 			UseOfMFC="2"
-			CharacterSet="1"
+			CharacterSet="2"
 			WholeProgramOptimization="1"
 			>
 			<Tool

+ 4 - 1
source/hook/WxService/stdafx.cpp

@@ -16,7 +16,6 @@ BOOL CreatePoolInstance()
 	{
 		CString strError = _T("");
 		strError.Format(_T("error = %d"), GetLastError());
-		//AfxMessageBox(strError);
 		return FALSE;
 	}
 
@@ -29,7 +28,11 @@ BOOL CreatePoolInstance()
 void FreelyfzodbcLibrary()
 {
 	if (g_hpool)
+	{
+		g_pAdoPool->ReleasePool();
+		g_pAdoPool->Release();
 		FreeLibrary(g_hpool);
+	}
 
 	g_hpool = NULL;
 	g_pAdoPool = NULL;