From: Stephen Morris Date: Wed, 24 Aug 2016 12:01:26 +0000 (+0100) Subject: [4494] Avoid referencing objects after destruction X-Git-Tag: trac4631_base~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f200756e540e2fa295cf80b33b03cb93cdd03d5;p=thirdparty%2Fkea.git [4494] Avoid referencing objects after destruction In some cases destructors were referencing objects in the logger that had been destroyed earlier, causing a segmentation violation. --- diff --git a/src/lib/log/logger_level_impl.cc b/src/lib/log/logger_level_impl.cc index d5cff064d0..ae8a3ed568 100644 --- a/src/lib/log/logger_level_impl.cc +++ b/src/lib/log/logger_level_impl.cc @@ -179,20 +179,18 @@ LoggerLevelImpl::logLevelFromString(const log4cplus::tstring& level) { // return the string DEBUG, else return the empty string. LoggerLevelImpl::LogLevelString LoggerLevelImpl::logLevelToString(log4cplus::LogLevel level) { - static const tstring debug_string("DEBUG"); - static const tstring empty_string; Level bindlevel = convertToBindLevel(level); Severity& severity = bindlevel.severity; int& dbglevel = bindlevel.dbglevel; if ((severity == DEBUG) && ((dbglevel >= MIN_DEBUG_LEVEL) && (dbglevel <= MAX_DEBUG_LEVEL))) { - return (debug_string); + return (tstring("DEBUG")); } // Unknown, so return empty string for log4cplus to try other conversion // functions. - return (empty_string); + return (tstring()); } // Initialization. Register the conversion functions with the LogLevelManager. diff --git a/src/lib/log/logger_level_impl.h b/src/lib/log/logger_level_impl.h index 9d4dd4b0aa..20321bd328 100644 --- a/src/lib/log/logger_level_impl.h +++ b/src/lib/log/logger_level_impl.h @@ -58,11 +58,7 @@ namespace log { class LoggerLevelImpl { public: -#if (LOG4CPLUS_VERSION >= LOG4CPLUS_MAKE_VERSION(1, 1, 0)) - typedef log4cplus::tstring const & LogLevelString; -#else - typedef log4cplus::tstring LogLevelString; -#endif +typedef log4cplus::tstring LogLevelString; /// \brief Convert Kea level to log4cplus logging level /// diff --git a/src/lib/log/message_dictionary.cc b/src/lib/log/message_dictionary.cc index f9c5ee3b20..3d670e256a 100644 --- a/src/lib/log/message_dictionary.cc +++ b/src/lib/log/message_dictionary.cc @@ -13,6 +13,11 @@ using namespace std; namespace isc { namespace log { +// Constructor + +MessageDictionary::MessageDictionary() : dictionary_(), empty_("") { +} + // (Virtual) Destructor MessageDictionary::~MessageDictionary() { @@ -91,10 +96,9 @@ MessageDictionary::load(const char* messages[]) { const string& MessageDictionary::getText(const std::string& ident) const { - static const string empty(""); Dictionary::const_iterator i = dictionary_.find(ident); if (i == dictionary_.end()) { - return (empty); + return (empty_); } else { return (i->second); diff --git a/src/lib/log/message_dictionary.h b/src/lib/log/message_dictionary.h index ac8541a863..7863dc6a3e 100644 --- a/src/lib/log/message_dictionary.h +++ b/src/lib/log/message_dictionary.h @@ -50,7 +50,8 @@ public: typedef std::map Dictionary; typedef Dictionary::const_iterator const_iterator; - // Default constructor and assignment operator are OK for this class + /// \brief Constructor + MessageDictionary(); /// \brief Virtual Destructor virtual ~MessageDictionary(); @@ -198,6 +199,7 @@ public: private: Dictionary dictionary_; ///< Holds the ID to text lookups + const std::string empty_; ///< Empty string }; } // namespace log