]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4494] Avoid referencing objects after destruction
authorStephen Morris <stephen@isc.org>
Wed, 24 Aug 2016 12:01:26 +0000 (13:01 +0100)
committerStephen Morris <stephen@isc.org>
Wed, 24 Aug 2016 12:01:26 +0000 (13:01 +0100)
In some cases destructors were referencing objects in the logger
that had been destroyed earlier, causing a segmentation violation.

src/lib/log/logger_level_impl.cc
src/lib/log/logger_level_impl.h
src/lib/log/message_dictionary.cc
src/lib/log/message_dictionary.h

index d5cff064d0db63516012544d18538c14c6a512c6..ae8a3ed568b33a46e816bdc2a1c8c03c33b0aaec 100644 (file)
@@ -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.
index 9d4dd4b0aa3cc041f0b6758be2e6661d3663da31..20321bd328e2db864937bb5d464991129cd67a7d 100644 (file)
@@ -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
     ///
index f9c5ee3b200032ff2dd211a8b751014bcec8281f..3d670e256a00644e2351db6d4ea43c54da9ed374 100644 (file)
@@ -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);
index ac8541a86365bdce93fde5276b41a39e0098fb02..7863dc6a3e4468057584c499c3cf5fb2cb21ead4 100644 (file)
@@ -50,7 +50,8 @@ public:
     typedef std::map<std::string, std::string> 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