From 00a206d45303b6fe48168eec86bfd9c064ec2123 Mon Sep 17 00:00:00 2001 From: Geoff Phillips Date: Mon, 21 Oct 2024 13:56:56 +0200 Subject: [PATCH] Fix two destruction order issues causing segfaults during shutdown 1. `application_impl::~application_impl` calls the `plugin_manager` when `VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS` is not defined. Therefore it should hold a `shared_ptr` to it instead of calling `plugin_manager::get()` in the destructor, in order to prevent the global `the_plugin_manager__` instance being destroyed before it is. 2. `routing_manager_impl::~routing_manager_impl` calls `utility` functions. Therefore destroy the `routing_` instance in `application_impl::shutdown` to ensure that this happens before the `utility` global variables are destroyed. --- .../runtime/include/application_impl.hpp | 8 ++++++++ implementation/runtime/src/application_impl.cpp | 17 +++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/implementation/runtime/include/application_impl.hpp b/implementation/runtime/include/application_impl.hpp index 082c21471..ec158e216 100644 --- a/implementation/runtime/include/application_impl.hpp +++ b/implementation/runtime/include/application_impl.hpp @@ -34,6 +34,10 @@ #include #include +#ifndef VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS +#include +#endif + #ifdef ANDROID #include "../../configuration/include/internal_android.hpp" #else @@ -382,6 +386,10 @@ class application_impl: public application, std::string path_; std::shared_ptr configuration_; +#ifndef VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS + std::shared_ptr plugin_manager_; +#endif + boost::asio::io_context io_; std::set > io_threads_; std::shared_ptr>( io_.get_executor())), @@ -71,7 +74,7 @@ application_impl::~application_impl() { #ifndef VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS if(configuration_) { - auto its_plugin = plugin_manager::get()->get_plugin( + auto its_plugin = plugin_manager_->get_plugin( plugin_type_e::CONFIGURATION_PLUGIN, VSOMEIP_CFG_LIBRARY); if (its_plugin) { auto its_configuration_plugin @@ -142,7 +145,7 @@ bool application_impl::init() { // TODO: Add loading of custom configuration module } else { // load default module #ifndef VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS - auto its_plugin = plugin_manager::get()->get_plugin( + auto its_plugin = plugin_manager_->get_plugin( plugin_type_e::CONFIGURATION_PLUGIN, VSOMEIP_CFG_LIBRARY); if (its_plugin) { auto its_configuration_plugin @@ -354,7 +357,7 @@ bool application_impl::init() { auto its_app_plugin_info = its_plugins.find(plugin_type_e::APPLICATION_PLUGIN); if (its_app_plugin_info != its_plugins.end()) { for (auto its_library : its_app_plugin_info->second) { - auto its_application_plugin = plugin_manager::get()->get_plugin( + auto its_application_plugin = plugin_manager_->get_plugin( plugin_type_e::APPLICATION_PLUGIN, its_library); if (its_application_plugin) { VSOMEIP_INFO << "Client 0x" << std::hex << get_client() @@ -486,7 +489,7 @@ void application_impl::start() { auto its_app_plugin_info = its_plugins.find(plugin_type_e::APPLICATION_PLUGIN); if (its_app_plugin_info != its_plugins.end()) { for (const auto& its_library : its_app_plugin_info->second) { - auto its_application_plugin = plugin_manager::get()->get_plugin( + auto its_application_plugin = plugin_manager_->get_plugin( plugin_type_e::APPLICATION_PLUGIN, its_library); if (its_application_plugin) { std::dynamic_pointer_cast(its_application_plugin)-> @@ -562,7 +565,7 @@ void application_impl::stop() { auto its_app_plugin_info = its_plugins.find(plugin_type_e::APPLICATION_PLUGIN); if (its_app_plugin_info != its_plugins.end()) { for (const auto& its_library : its_app_plugin_info->second) { - auto its_application_plugin = plugin_manager::get()->get_plugin( + auto its_application_plugin = plugin_manager_->get_plugin( plugin_type_e::APPLICATION_PLUGIN, its_library); if (its_application_plugin) { std::dynamic_pointer_cast(its_application_plugin)-> @@ -2251,8 +2254,10 @@ void application_impl::shutdown() { } try { - if (routing_) + if (routing_) { routing_->stop(); + routing_.reset(); + } } catch (const std::exception &e) { VSOMEIP_ERROR << "application_impl::" << __func__ << ": stopping routing, " << " catched exception: " << e.what();