table: Pit::erase accepts Entry* instead of shared_ptr

refs #3164

Change-Id: I9ff47c80865da42b09870c632707dffd78ed76b9
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 89ce166..4fc9c38 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -312,7 +312,7 @@
 
   // PIT delete
   this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
-  m_pit.erase(pitEntry);
+  m_pit.erase(pitEntry.get());
 }
 
 void
diff --git a/daemon/table/name-tree-entry.cpp b/daemon/table/name-tree-entry.cpp
index 5721e22..8d33a89 100644
--- a/daemon/table/name-tree-entry.cpp
+++ b/daemon/table/name-tree-entry.cpp
@@ -95,17 +95,18 @@
 }
 
 void
-Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
+Entry::erasePitEntry(pit::Entry* pitEntry)
 {
   BOOST_ASSERT(pitEntry != nullptr);
   BOOST_ASSERT(pitEntry->m_nameTreeEntry == this);
 
-  auto it = std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry);
+  auto it = std::find_if(m_pitEntries.begin(), m_pitEntries.end(),
+    [pitEntry] (const shared_ptr<pit::Entry>& pitEntry2) { return pitEntry2.get() == pitEntry; });
   BOOST_ASSERT(it != m_pitEntries.end());
 
-  *it = m_pitEntries.back();
+  pitEntry->m_nameTreeEntry = nullptr; // must be done before pitEntry is deallocated
+  *it = m_pitEntries.back(); // may deallocate pitEntry
   m_pitEntries.pop_back();
-  pitEntry->m_nameTreeEntry = nullptr;
 }
 
 void
diff --git a/daemon/table/name-tree-entry.hpp b/daemon/table/name-tree-entry.hpp
index d481a5e..b36aae9 100644
--- a/daemon/table/name-tree-entry.hpp
+++ b/daemon/table/name-tree-entry.hpp
@@ -132,7 +132,7 @@
   insertPitEntry(shared_ptr<pit::Entry> pitEntry);
 
   void
-  erasePitEntry(shared_ptr<pit::Entry> pitEntry);
+  erasePitEntry(pit::Entry* pitEntry);
 
   measurements::Entry*
   getMeasurementsEntry() const
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index bf17e96..91bc5a8 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -100,7 +100,7 @@
 }
 
 void
-Pit::erase(shared_ptr<Entry> entry, bool canDeleteNte)
+Pit::erase(Entry* entry, bool canDeleteNte)
 {
   name_tree::Entry* nte = m_nameTree.getEntry(*entry);
   BOOST_ASSERT(nte != nullptr);
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index 1df3380..8e6c9f1 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -84,10 +84,10 @@
   DataMatchResult
   findAllDataMatches(const Data& data) const;
 
-  /** \brief erases a PIT Entry
+  /** \brief deletes an entry
    */
   void
-  erase(shared_ptr<Entry> entry)
+  erase(Entry* entry)
   {
     this->erase(entry, true);
   }
@@ -118,10 +118,8 @@
   }
 
 private:
-  /** \brief erases a PIT Entry
-   */
   void
-  erase(shared_ptr<Entry> pitEntry, bool canDeleteNte);
+  erase(Entry* pitEntry, bool canDeleteNte);
 
   /** \brief finds or inserts a PIT entry for Interest
    *  \param interest the Interest; must be created with make_shared if allowInsert