Преглед изворни кода

Debug下,curlib+openssl存在内存泄漏,网友说静态编译的openssl容易造成内存泄漏;改Release下压测看看结果。

SCBC.SAT2 пре 5 година
родитељ
комит
6c46c18a6c

+ 6 - 3
scbc.tools/scbc.tools.sln

@@ -13,20 +13,23 @@ Global
 		Debug|Win32 = Debug|Win32
 		DebugExe|Win32 = DebugExe|Win32
 		Release|Win32 = Release|Win32
+		ReleaseExe|Win32 = ReleaseExe|Win32
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.Debug|Win32.ActiveCfg = Debug|Win32
 		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.Debug|Win32.Build.0 = Debug|Win32
-		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.DebugExe|Win32.ActiveCfg = DebugExe|Win32
-		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.DebugExe|Win32.Build.0 = DebugExe|Win32
+		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.DebugExe|Win32.ActiveCfg = ReleaseExe|Win32
+		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.DebugExe|Win32.Build.0 = ReleaseExe|Win32
 		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.Release|Win32.ActiveCfg = Release|Win32
 		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.Release|Win32.Build.0 = Release|Win32
+		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.ReleaseExe|Win32.ActiveCfg = ReleaseExe|Win32
+		{95CA9F08-85F6-4FD6-A80D-15EEC854B118}.ReleaseExe|Win32.Build.0 = ReleaseExe|Win32
 		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.Debug|Win32.ActiveCfg = Debug|Win32
 		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.Debug|Win32.Build.0 = Debug|Win32
 		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.DebugExe|Win32.ActiveCfg = Debug|Win32
-		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.DebugExe|Win32.Build.0 = Debug|Win32
 		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.Release|Win32.ActiveCfg = Release|Win32
 		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.Release|Win32.Build.0 = Release|Win32
+		{962E22D9-0EDB-4D96-874D-80FC8C2A2C68}.ReleaseExe|Win32.ActiveCfg = Debug|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 43 - 3
scbc.tools/scbc.tools/SDK.cpp

@@ -16,12 +16,12 @@ m_hThreadReport(NULL)
 {
 	Global::Init();
 	Global::GetMacAddress();
-	m_curl.Initialize();
 }
 
 CSDK::~CSDK(void)
 {
-	
+	EndDowloadThread();
+	EndReportThread();
 }
 
 int CSDK::QueryMidInfo(std::string order)
@@ -249,7 +249,9 @@ int CSDK::GetMidInfo(std::string order, STMid &mid)
 	content.append(order);
 	//content.append("&mac=");
 	//content.append(Global::g_strMacs);
-	if ( m_curl.Posts(url, content, result) == CURLE_OK)
+	CCurlClient curl;
+	curl.Initialize();
+	if ( curl.Posts(url, content, result) == CURLE_OK)
 	{
 		// ½âÎöjson×Ö·û´®;
 		cJSON *pJson = cJSON_Parse(result.c_str());
@@ -469,6 +471,25 @@ DWORD CSDK::ThreadDownload(LPVOID lpParam)
 	return 0L;
 }
 
+void CSDK::EndDowloadThread()
+{
+	if ( m_hDownloadEvent )
+	{
+		SetEvent(m_hDownloadEvent);
+	}
+
+	if ( m_hThreadDownload)
+	{
+		WaitForSingleObject(m_hThreadDownload, INFINITE);
+		CloseHandle(m_hThreadDownload);
+		m_hThreadDownload = NULL;
+
+		if ( m_hDownloadEvent )
+			CloseHandle(m_hDownloadEvent);
+		m_hDownloadEvent = NULL;
+	}		 
+}
+
 DWORD CSDK::ThreadReport(LPVOID lpParam)
 {
 	CSDK *that = (CSDK*)lpParam;
@@ -479,4 +500,23 @@ DWORD CSDK::ThreadReport(LPVOID lpParam)
 	} while (WaitForSingleObject(that->m_hReportEvent, 3000) == WAIT_TIMEOUT );
 
 	return 0L;
+}
+
+void CSDK::EndReportThread()
+{
+	if ( m_hReportEvent )
+	{
+		SetEvent(m_hReportEvent);
+	}
+
+	if ( m_hThreadReport)
+	{
+		WaitForSingleObject(m_hThreadReport, INFINITE);
+		CloseHandle(m_hThreadReport);
+		m_hThreadReport = NULL;
+
+		if ( m_hReportEvent )
+			CloseHandle(m_hReportEvent);
+		m_hReportEvent = NULL;
+	}		 
 }

+ 2 - 1
scbc.tools/scbc.tools/SDK.h

@@ -25,7 +25,6 @@ public:
 	static void ParserKey(std::string file, std::vector<STKeys> &vtKyes, std::string pid);
 	static bool ParserSNKey(std::string json, SNKeys &snKey);
 private:
-	CCurlClient m_curl;
 	static std::list<STMid> m_vtMidTask;
 	static void AddDownloadTask(STMid &mid);
 	static BOOL PopDownloadTask(STMid &mid);
@@ -34,10 +33,12 @@ private:
 	HANDLE m_hDownloadEvent;
 	HANDLE m_hThreadDownload;
 	static DWORD WINAPI ThreadDownload(LPVOID lpParam);
+	void EndDowloadThread();
 
 	HANDLE m_hReportEvent;
 	HANDLE m_hThreadReport;
 	static DWORD WINAPI ThreadReport(LPVOID lpParam);
+	void EndReportThread();
 };
 
 #endif

+ 23 - 6
scbc.tools/scbc.tools/scbc.tools.cpp

@@ -19,16 +19,29 @@ CWinApp theApp;
 
 using namespace std;
 
-void TEST_GetMidInfo()
+void TEST_Download()
 {
-	CSDK sdk;
-	STMid mid;
-	if ( sdk.DownloadMidData("IDL144240G") )
+	printf("开始压测下载……\n");
+	TCHAR szDir[MAX_PATH] = {0};
+	_stprintf_s(szDir, _T("E:\\bin\\%s.exe"), "SunloginClient");
+	for (int i = 0; i < 10000; i++)
 	{
-		
+		CCurlClient curl;
+		curl.Initialize();
+		//_stprintf_s(szDir, _T("E:\\bin\\%s.exe"), CTime::GetCurrentTime().Format("%Y%m%d%H%M%S").GetString());
+		curl.DownloadEx("http://download.oray.com/sunlogin/windows/SunloginClient10.1.exe", szDir);
+		DeleteFile(szDir);
+		printf("完成第%d次\n", i);
 	}
+	printf("结束压测下载……\n");
+}
 
-	system("pause");
+void TEST_GetMidInfo()
+{
+	CSDK sdk;
+	STMid mid;
+	sdk.DownloadMidData("IDL144240G");
+	Sleep(60000);
 }
 
 void TEST_InsertMidInfo()
@@ -227,7 +240,10 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	{
 		std::string md5 = GetFileMD5("D:\\bin\\scbc.tools\\scbc.tools.pdb");
 		// TODO: 在此处为应用程序的行为编写代码。
+		Sleep(5000);
+		TEST_Download();
 		//TEST_GetMidInfo();
+		/*
 		TEST_InsertMidInfo();
 		TEST_QueryMidInfo();
 		TEST_InertKeys();
@@ -237,6 +253,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 		TEST_QueryUnReportKey();
 		TEST_QueryLogInfo();
 		TEST_QueryUnReportLogInfo();
+		*/
 	}
 
 	system("pause");

+ 100 - 1
scbc.tools/scbc.tools/scbc.tools.vcproj

@@ -169,7 +169,7 @@
 			/>
 			<Tool
 				Name="VCPostBuildEventTool"
-				CommandLine="copy $(TargetDir)\$(SolutionName).lib $(SolutionDir)\test\$(ProjectName).lib /y/a&#x0D;&#x0A;copy $(TargetPath) $(SolutionDir)\test\$(TargetFileName) /y/a&#x0D;&#x0A;copy $(SolutionDir)$(SolutionName)\TableInfo.h $(SolutionDir)\test\TableInfo.h /y/a&#x0D;&#x0A;copy $(SolutionDir)$(SolutionName)\$(SolutionName).h $(SolutionDir)\test\$(SolutionName).h  /y/a"
+				CommandLine="copy $(TargetDir)\$(SolutionName).lib $(SolutionDir)\test\$(ProjectName).lib /y/a&#x0D;&#x0A;copy $(TargetPath) $(SolutionDir)\test\$(TargetFileName) /y/a&#x0D;&#x0A;copy $(SolutionDir)$(SolutionName)\TableInfo.h $(SolutionDir)\test\TableInfo.h /y/a&#x0D;&#x0A;copy $(SolutionDir)$(SolutionName)\$(SolutionName).h $(SolutionDir)\test\$(SolutionName).h  /y/a&#x0D;&#x0A;"
 			/>
 		</Configuration>
 		<Configuration
@@ -247,6 +247,81 @@
 				Name="VCPostBuildEventTool"
 			/>
 		</Configuration>
+		<Configuration
+			Name="ReleaseExe|Win32"
+			OutputDirectory="..\..\..\bin\$(ProjectName)"
+			IntermediateDirectory="$(OutDir)\$(ConfigurationName)"
+			ConfigurationType="1"
+			UseOfMFC="2"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\cJson;..\filehelper;..\Include;..\Log4C;..\MD5"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SCBCTOOLS_EXPORTS;LOG4C_ENABLE;CURL_STATICLIB;TEST_MODE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="2"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="crypt32.lib ws2_32.lib winmm.lib wldap32.lib libcurl.lib libeay32.lib sqlite3.lib ssleay32.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="..\lib"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
 	</Configurations>
 	<References>
 	</References>
@@ -295,6 +370,14 @@
 						UsePrecompiledHeader="1"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="ReleaseExe|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
 			</File>
 		</Filter>
 		<Filter
@@ -403,6 +486,14 @@
 						UsePrecompiledHeader="0"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="ReleaseExe|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="0"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath=".\tinyxml2.h"
@@ -463,6 +554,14 @@
 						UsePrecompiledHeader="0"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="ReleaseExe|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="0"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\cJson\cJSON.h"