From 86bc1cd1424b38d42fe1bf4418a6ef33169951c4 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Mon, 2 Dec 2024 14:47:46 +0100 Subject: [PATCH] Fix possible race condition at exit with OpenSSL --- src/impl/tls.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/impl/tls.cpp b/src/impl/tls.cpp index bc9d7ba1a..60dbb2cf7 100644 --- a/src/impl/tls.cpp +++ b/src/impl/tls.cpp @@ -158,7 +158,11 @@ void init() { std::lock_guard lock(mutex); if (!std::exchange(done, true)) { - OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, nullptr); + uint64_t ssl_opts = OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS; +#ifdef OPENSSL_INIT_NO_ATEXIT + ssl_opts |= OPENSSL_INIT_NO_ATEXIT; +#endif + OPENSSL_init_ssl(ssl_opts, nullptr); OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, nullptr); } }