Browse Source

[3823] Addressed review comments.

Do not remove duplicates if other MessageInitializers held them.
Also, do not remove message from the dictionary if removing the
duplicate.
Marcin Siodelski 10 years ago
parent
commit
65e2935144

+ 13 - 2
src/lib/log/message_initializer.cc

@@ -1,3 +1,4 @@
+
 // Copyright (C) 2011,2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
@@ -77,8 +78,18 @@ MessageInitializer::~MessageInitializer() {
         // the dictionary and/or duplicates.
         int i = 0;
         while (values_[i]) {
-            global_logger_duplicates_->remove(values_[i]);
-            global_dictionary_->erase(values_[i], values_[i + 1]);
+            // Check if the unloaded message is registered as duplicate. If it is,
+            // remove it from the duplicates list.
+            LoggerDuplicatesList::const_iterator dup =
+                std::find(global_logger_duplicates_->begin(),
+                          global_logger_duplicates_->end(),
+                          values_[i]);
+            if (dup != global_logger_duplicates_->end()) {
+                global_logger_duplicates_->erase(dup);
+
+            } else {
+                global_dictionary_->erase(values_[i], values_[i + 1]);
+            }
             i += 2;
         }
     }

+ 5 - 4
src/lib/log/tests/message_initializer_1_unittest.cc

@@ -45,7 +45,7 @@ const char* values3[] = {
 };
 
 const char* values4[] = {
-    "GLOBAL8", "global message eight bis",
+    "GLOBAL8", "global message eight",
     "GLOBAL9", "global message nine",
     NULL
 };
@@ -119,11 +119,12 @@ TEST(MessageInitializerTest1, dynamicLoadUnload) {
     EXPECT_EQ("global message eight", global->getText("GLOBAL8"));
     EXPECT_EQ("global message nine", global->getText("GLOBAL9"));
 
-    // Destroy the first initializer. The first two messages should
-    // be unregistered.
+    // Destroy the first initializer. The first message should be removed.
+    // The second message should not be removed because it is also held
+    // by another object.
     init1.reset();
     EXPECT_TRUE(global->getText("GLOBAL7").empty());
-    EXPECT_TRUE(global->getText("GLOBAL8").empty());
+    EXPECT_EQ("global message eight", global->getText("GLOBAL8"));
     EXPECT_EQ("global message nine", global->getText("GLOBAL9"));
 
     // Destroy the second initializer. Now, all messages should be