Skip to content

Commit

Permalink
Refs #22024: Make OpenSSLInit Mayers singleton
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL committed Nov 5, 2024
1 parent a300afe commit bc5089c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/cpp/rtps/RTPSDomainImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <rtps/reader/BaseReader.hpp>
#include <rtps/reader/LocalReaderPointer.hpp>
#include <security/OpenSSLInit.hpp>
#include <rtps/writer/BaseWriter.hpp>
#include <utils/shared_memory/BoostAtExitRegistry.hpp>
#include <utils/SystemInfo.hpp>
Expand Down Expand Up @@ -286,6 +287,8 @@ class RTPSDomainImpl
BoostAtExitRegistry::
get_instance() };

std::shared_ptr<security::OpenSSLInit> openssl_singleton_handler_{ security::OpenSSLInit::get_instance() };

std::mutex m_mutex;

std::vector<t_p_RTPSParticipant> m_RTPSParticipants;
Expand Down
1 change: 0 additions & 1 deletion src/cpp/rtps/security/SecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ SecurityManager::SecurityManager(
participant->get_attributes().allocation.data_limits})
{
assert(participant != nullptr);
static OpenSSLInit openssl_init;
}

SecurityManager::~SecurityManager()
Expand Down
25 changes: 21 additions & 4 deletions src/cpp/security/OpenSSLInit.hpp
Original file line number Diff line number Diff line change
@@ -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 <memory>

#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/rand.h>
Expand Down Expand Up @@ -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<OpenSSLInit> get_instance()
{
static auto instance = std::make_shared<OpenSSLInit>();
return instance;
}
};

} // namespace security
Expand Down

0 comments on commit bc5089c

Please sign in to comment.