From 5a7c68e3c9e9cf3f888761e679beb3ba251bf68b Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 28 Aug 2019 15:59:45 +0300 Subject: [PATCH] MXS-2612 Ensure that destructor order does not matter The new configuration system relieas upon static varibles being used for declaring what arguments a particular module uses. To ensure that the destruction order does not matter, we redundantly store the needed data (the name). --- include/maxscale/config2.hh | 7 ++++--- server/core/config2.cc | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/maxscale/config2.hh b/include/maxscale/config2.hh index 80ff88793..1ce9690f6 100644 --- a/include/maxscale/config2.hh +++ b/include/maxscale/config2.hh @@ -883,7 +883,7 @@ private: friend Type; void insert(Type* pValue); - void remove(Type* pValue); + void remove(Type* pValue, const std::string& name); private: std::string m_name; @@ -946,8 +946,9 @@ protected: Type(Configuration* pConfiguration, const Param* pParam); private: - Configuration& m_configuration; - const Param& m_param; + Configuration& m_configuration; + const Param& m_param; + const std::string m_name; }; /** diff --git a/server/core/config2.cc b/server/core/config2.cc index 3f87c5576..be10700a7 100644 --- a/server/core/config2.cc +++ b/server/core/config2.cc @@ -381,11 +381,12 @@ void Configuration::insert(Type* pValue) m_values.insert(make_pair(pValue->parameter().name(), pValue)); } -void Configuration::remove(Type* pValue) +void Configuration::remove(Type* pValue, const std::string& name) { - auto it = m_values.find(pValue->parameter().name()); + auto it = m_values.find(name); mxb_assert(it != m_values.end()); + mxb_assert(it->second == pValue); m_values.erase(it); } @@ -405,13 +406,16 @@ size_t Configuration::size() const Type::Type(Configuration* pConfiguration, const config::Param* pParam) : m_configuration(*pConfiguration) , m_param(*pParam) + , m_name(pParam->name()) { + // The name is copied, so that we have access to it in the destructor + // also in the case that Param happens to be destructed first. m_configuration.insert(this); } Type::~Type() { - m_configuration.remove(this); + m_configuration.remove(this, m_name); } const config::Param& Type::parameter() const