Commit 65e29351 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[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.
parent 87ee8e5d
// 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;
}
}
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment