diff options
author | Matt Caswell <matt@openssl.org> | 2018-11-16 17:26:23 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2019-01-04 13:19:39 +0000 |
commit | de2debc524e8de89a9e4e8cd890af3882cf1aaab (patch) | |
tree | f7d4cc1c8274c8659d6b125fb16b27a2d8455b42 /crypto | |
parent | 41999e7d358c3657a254b34b85fd9e948180529b (diff) |
Support _onexit() in preference to atexit() on Windows
This enables cleanup to happen on DLL unload instead of at process exit.
[extended tests]
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7647)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/init.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crypto/init.c b/crypto/init.c index 6b6bd71967..5e6be10fca 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -118,14 +118,28 @@ err: } 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; |