table: fix Fib::removeNextHopFromAllEntries invalidating NameTree iterator

refs #2177

Change-Id: I19b8234d94b804273404176d6751a91f082653b7
This commit is contained in:
Junxiao Shi authored and Junxiao Shi committed 2014-12-03 10:36:27 -08:00
1 parent 7726ae5182
commit 4b2e6cb321
2 files changed
+22 -11

No files matched your search

+6 -11
View File
@@ -143,26 +143,21 @@ Fib::erase(const fib::Entry& entry)
void
Fib::removeNextHopFromAllEntries(shared_ptr<Face> face)
{
shared_ptr<fib::Entry> toErase;
std::list<fib::Entry*> toErase;
auto&& enumerable = m_nameTree.fullEnumerate(&predicate_NameTreeEntry_hasFibEntry);
for (const name_tree::Entry& nte : enumerable) {
if (toErase != nullptr) {
this->erase(*toErase);
toErase.reset();
}
shared_ptr<fib::Entry> entry = nte.getFibEntry();
entry->removeNextHop(face);
if (!entry->hasNextHops()) {
toErase = entry;
// entry needs to be erased, but we must wait until next iteration
// to erase it because otherwise it would invalidate the iterator
toErase.push_back(entry.get());
// entry needs to be erased, but we must wait until the enumeration ends,
// because otherwise NameTree iterator would be invalidated
}
}
if (toErase != nullptr) {
this->erase(*toErase);
for (fib::Entry* entry : toErase) {
this->erase(*entry);
}
}