From bc5089c5e00abe3cf3ba20de8fe6513140c603cd Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 5 Nov 2024 15:07:04 +0100 Subject: [PATCH] Refs #22024: Make OpenSSLInit Mayers singleton Signed-off-by: Mario Dominguez --- src/cpp/rtps/RTPSDomainImpl.hpp | 3 +++ src/cpp/rtps/security/SecurityManager.cpp | 1 - src/cpp/security/OpenSSLInit.hpp | 25 +++++++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/cpp/rtps/RTPSDomainImpl.hpp b/src/cpp/rtps/RTPSDomainImpl.hpp index 0a5fe87b650..37ef9cbfbce 100644 --- a/src/cpp/rtps/RTPSDomainImpl.hpp +++ b/src/cpp/rtps/RTPSDomainImpl.hpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -286,6 +287,8 @@ class RTPSDomainImpl BoostAtExitRegistry:: get_instance() }; + std::shared_ptr openssl_singleton_handler_{ security::OpenSSLInit::get_instance() }; + std::mutex m_mutex; std::vector m_RTPSParticipants; diff --git a/src/cpp/rtps/security/SecurityManager.cpp b/src/cpp/rtps/security/SecurityManager.cpp index da687b940f6..f26c06144a1 100644 --- a/src/cpp/rtps/security/SecurityManager.cpp +++ b/src/cpp/rtps/security/SecurityManager.cpp @@ -106,7 +106,6 @@ SecurityManager::SecurityManager( participant->get_attributes().allocation.data_limits}) { assert(participant != nullptr); - static OpenSSLInit openssl_init; } SecurityManager::~SecurityManager() diff --git a/src/cpp/security/OpenSSLInit.hpp b/src/cpp/security/OpenSSLInit.hpp index fab1e0aba3d..0fe47aae62d 100644 --- a/src/cpp/security/OpenSSLInit.hpp +++ b/src/cpp/security/OpenSSLInit.hpp @@ -1,3 +1,19 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + #include #include #include @@ -28,12 +44,13 @@ class OpenSSLInit ERR_remove_thread_state(NULL); ENGINE_cleanup(); #endif // if OPENSSL_VERSION_NUMBER < 0x10000000L - RAND_cleanup(); - CRYPTO_cleanup_all_ex_data(); - ERR_free_strings(); - EVP_cleanup(); } + static std::shared_ptr get_instance() + { + static auto instance = std::make_shared(); + return instance; + } }; } // namespace security