rib: fix use-after-free in Rib::erase and RibManagerFixture::clearRib
Change-Id: Ia4c2211f6c48d852e3b73dc84e298d26ad14f708
Refs: #3787
diff --git a/tests/rib/rib-manager.t.cpp b/tests/rib/rib-manager.t.cpp
index 9bd8f72..f3df261 100644
--- a/tests/rib/rib-manager.t.cpp
+++ b/tests/rib/rib-manager.t.cpp
@@ -117,7 +117,7 @@
};
Name commandPrefix("/localhost/nfd/fib/add-nexthop");
- for (auto&& command : m_commands) {
+ for (const auto& command : m_commands) {
if (commandPrefix.isPrefixOf(command.getName())) {
replyFibAddCommand(command);
advanceClocks(time::milliseconds(1));
@@ -129,14 +129,11 @@
m_commands.clear();
}
- void clearRib()
+ void
+ clearRib()
{
while (!m_rib.empty()) {
- auto& name = m_rib.begin()->first;
- auto& routes = m_rib.begin()->second->getRoutes();
- while (!routes.empty()) {
- m_rib.erase(name, *routes.begin());
- }
+ m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin());
}
}