[winpr] add atexit calls for WLog and SSL providers
C11 atexit cleanup handler are used to call cleanup routines for WLog and SSL on program termination. This removes false positives when using ASAN runtime memory debugger
This commit is contained in:
parent
481ba1581c
commit
ba98aa0a8c
@ -282,7 +282,12 @@ static BOOL winpr_enable_fips(DWORD flags)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK _winpr_openssl_initialize(PINIT_ONCE once, PVOID param, PVOID* context)
|
||||
static void winpr_openssl_cleanup(void)
|
||||
{
|
||||
winpr_CleanupSSL(WINPR_SSL_INIT_DEFAULT);
|
||||
}
|
||||
|
||||
static BOOL CALLBACK winpr_openssl_initialize(PINIT_ONCE once, PVOID param, PVOID* context)
|
||||
{
|
||||
DWORD flags = param ? *(PDWORD)param : WINPR_SSL_INIT_DEFAULT;
|
||||
|
||||
@ -333,6 +338,7 @@ static BOOL CALLBACK _winpr_openssl_initialize(PINIT_ONCE once, PVOID param, PVO
|
||||
}
|
||||
#endif
|
||||
|
||||
atexit(winpr_openssl_cleanup);
|
||||
g_winpr_openssl_initialized_by_winpr = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
@ -343,12 +349,30 @@ BOOL winpr_InitializeSSL(DWORD flags)
|
||||
{
|
||||
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
|
||||
|
||||
if (!InitOnceExecuteOnce(&once, _winpr_openssl_initialize, &flags, NULL))
|
||||
if (!InitOnceExecuteOnce(&once, winpr_openssl_initialize, &flags, NULL))
|
||||
return FALSE;
|
||||
|
||||
return winpr_enable_fips(flags);
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
|
||||
static int unload(OSSL_PROVIDER* provider, void* data)
|
||||
{
|
||||
if (!provider)
|
||||
return 1;
|
||||
const char* name = OSSL_PROVIDER_get0_name(provider);
|
||||
if (!name)
|
||||
return 1;
|
||||
|
||||
OSSL_LIB_CTX* ctx = OSSL_LIB_CTX_get0_global_default();
|
||||
const int rc = OSSL_PROVIDER_available(ctx, name);
|
||||
if (rc < 1)
|
||||
return 1;
|
||||
OSSL_PROVIDER_unload(provider);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL winpr_CleanupSSL(DWORD flags)
|
||||
{
|
||||
if (flags & WINPR_SSL_CLEANUP_GLOBAL)
|
||||
@ -386,10 +410,10 @@ BOOL winpr_CleanupSSL(DWORD flags)
|
||||
|
||||
#endif
|
||||
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
|
||||
OSSL_PROVIDER_unload(s_winpr_openssl_provider_fips);
|
||||
OSSL_PROVIDER_unload(s_winpr_openssl_provider_legacy);
|
||||
OSSL_PROVIDER_unload(s_winpr_openssl_provider_default);
|
||||
OSSL_LIB_CTX* ctx = OSSL_LIB_CTX_get0_global_default();
|
||||
OSSL_PROVIDER_do_all(ctx, unload, NULL);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -167,9 +167,8 @@ static BOOL CALLBACK WLog_InitializeRoot(PINIT_ONCE InitOnce, PVOID Parameter, P
|
||||
if (!WLog_ParseFilters(g_RootLog))
|
||||
goto fail;
|
||||
|
||||
#if defined(_WIN32)
|
||||
atexit(WLog_Uninit_);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
fail:
|
||||
WLog_Uninit_();
|
||||
|
Loading…
Reference in New Issue
Block a user