From 7cfd634814762a3cd8a22fce9a4ec6d47bb8f536 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 22 May 2015 12:53:41 +0000 Subject: fix for a crash inside http request destruction git-svn-id: http://svn.miranda-ng.org/main/trunk@13754 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/netlib/netlib.cpp | 1 - src/modules/netlib/netlib.h | 1 - src/modules/netlib/netlibsecurity.cpp | 30 ++++++++++-------------------- 3 files changed, 10 insertions(+), 22 deletions(-) (limited to 'src/modules/netlib') diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp index bc833c9195..a900c77f93 100644 --- a/src/modules/netlib/netlib.cpp +++ b/src/modules/netlib/netlib.cpp @@ -415,7 +415,6 @@ void UnloadNetlibModule(void) if (!bModuleInitialized || hConnectionHeaderMutex == NULL) return; NetlibUnloadIeProxy(); - NetlibSecurityDestroy(); NetlibUPnPDestroy(); NetlibLogShutdown(); diff --git a/src/modules/netlib/netlib.h b/src/modules/netlib/netlib.h index 2586298c8d..949d1755b2 100644 --- a/src/modules/netlib/netlib.h +++ b/src/modules/netlib/netlib.h @@ -203,7 +203,6 @@ void NetlibUPnPDestroy(void); //netlibsecurity.c void NetlibSecurityInit(void); -void NetlibSecurityDestroy(void); void NetlibDestroySecurityProvider(HANDLE hSecurity); HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrincipal); HANDLE NetlibInitSecurityProvider(const char* szProvider, const char* szPrincipal); diff --git a/src/modules/netlib/netlibsecurity.cpp b/src/modules/netlib/netlibsecurity.cpp index 10a322453d..6533a1fa5f 100644 --- a/src/modules/netlib/netlibsecurity.cpp +++ b/src/modules/netlib/netlibsecurity.cpp @@ -61,7 +61,7 @@ struct NtlmType2packet }; static unsigned secCnt = 0, ntlmCnt = 0; -static HANDLE hSecMutex; +static mir_cs csSec; static void ReportSecError(SECURITY_STATUS scRet, int line) { @@ -116,7 +116,7 @@ HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrinci return hNtlm; } - WaitForSingleObject(hSecMutex, INFINITE); + mir_cslock lck(csSec); if (secCnt == 0) { LoadSecurityLibrary(); @@ -143,8 +143,6 @@ HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrinci ntlmCnt++; } } - - ReleaseMutex(hSecMutex); return hSecurity; } @@ -158,24 +156,23 @@ void NetlibDestroySecurityProvider(HANDLE hSecurity) if (hSecurity == NULL) return; - WaitForSingleObject(hSecMutex, INFINITE); + mir_cslock lck(csSec); if (ntlmCnt != 0) { NtlmHandleType* hNtlm = (NtlmHandleType*)hSecurity; - if (SecIsValidHandle(&hNtlm->hClientContext)) g_pSSPI->DeleteSecurityContext(&hNtlm->hClientContext); - if (SecIsValidHandle(&hNtlm->hClientCredential)) g_pSSPI->FreeCredentialsHandle(&hNtlm->hClientCredential); - mir_free(hNtlm->szProvider); - mir_free(hNtlm->szPrincipal); + if (hNtlm != NULL) { + if (SecIsValidHandle(&hNtlm->hClientContext)) g_pSSPI->DeleteSecurityContext(&hNtlm->hClientContext); + if (SecIsValidHandle(&hNtlm->hClientCredential)) g_pSSPI->FreeCredentialsHandle(&hNtlm->hClientCredential); + mir_free(hNtlm->szProvider); + mir_free(hNtlm->szPrincipal); + mir_free(hNtlm); + } --ntlmCnt; - - mir_free(hNtlm); } if (secCnt && --secCnt == 0) FreeSecurityLibrary(); - - ReleaseMutex(hSecMutex); } char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chlsz) @@ -458,16 +455,9 @@ static INT_PTR NtlmCreateResponseService2(WPARAM wParam, LPARAM lParam) void NetlibSecurityInit(void) { - hSecMutex = CreateMutex(NULL, FALSE, NULL); - CreateServiceFunction(MS_NETLIB_INITSECURITYPROVIDER, InitSecurityProviderService); CreateServiceFunction(MS_NETLIB_INITSECURITYPROVIDER2, InitSecurityProviderService2); CreateServiceFunction(MS_NETLIB_DESTROYSECURITYPROVIDER, DestroySecurityProviderService); CreateServiceFunction(MS_NETLIB_NTLMCREATERESPONSE, NtlmCreateResponseService); CreateServiceFunction(MS_NETLIB_NTLMCREATERESPONSE2, NtlmCreateResponseService2); } - -void NetlibSecurityDestroy(void) -{ - CloseHandle(hSecMutex); -} -- cgit v1.2.3