table: Fix segfault during Fib::removeNextHopFromAllEntries

Change-Id: I905a3c0da2f2a9197942cfeba7fd698b779e6e4a
Refs: #1816
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 3672b66..660ae72 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -144,8 +144,11 @@
 Fib::removeNextHopFromAllEntries(shared_ptr<Face> face)
 {
   for (NameTree::const_iterator it = m_nameTree.fullEnumerate(
-       &predicate_NameTreeEntry_hasFibEntry); it != m_nameTree.end(); ++it) {
+       &predicate_NameTreeEntry_hasFibEntry); it != m_nameTree.end();) {
     shared_ptr<fib::Entry> entry = it->getFibEntry();
+
+    ++it; // need to be advance before `erase`, otherwise the iterator can be invalidated
+
     entry->removeNextHop(face);
     if (!entry->hasNextHops()) {
       this->erase(*entry);