Skip to content

Commit

Permalink
Support _onexit() in preference to atexit() on Windows
Browse files Browse the repository at this point in the history
This enables cleanup to happen on DLL unload instead of at process exit.

[extended tests]

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from #7983)
  • Loading branch information
mattcaswell committed Jan 4, 2019
1 parent 6b97cc6 commit 56806f4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crypto/init.c
Expand Up @@ -118,14 +118,28 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base)
}

static CRYPTO_ONCE register_atexit = CRYPTO_ONCE_STATIC_INIT;
#if !defined(OPENSSL_SYS_UEFI) && defined(_WIN32)
static int win32atexit(void)
{
OPENSSL_cleanup();
return 0;
}
#endif

DEFINE_RUN_ONCE_STATIC(ossl_init_register_atexit)
{
# ifdef OPENSSL_INIT_DEBUG
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_register_atexit()\n");
# endif
#endif
#ifndef OPENSSL_SYS_UEFI
# ifdef _WIN32
/* We use _onexit() in preference because it gets called on DLL unload */
if (_onexit(win32atexit) == NULL)
return 0;
# else
if (atexit(OPENSSL_cleanup) != 0)
return 0;
# endif
#endif

return 1;
Expand Down

0 comments on commit 56806f4

Please sign in to comment.