diff -r a3ef4e9615c0 src/internet/model/arp-cache.cc --- a/src/internet/model/arp-cache.cc Sun Sep 13 08:41:50 2015 -0700 +++ b/src/internet/model/arp-cache.cc Sun Sep 13 19:13:02 2015 -0700 @@ -99,7 +99,16 @@ ArpCache::DoDispose (void) { NS_LOG_FUNCTION (this); - Flush (); + for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) + { + delete (*i).second; + } + m_arpCache.erase (m_arpCache.begin (), m_arpCache.end ()); + if (m_waitReplyTimer.IsRunning ()) + { + NS_LOG_LOGIC ("Stopping WaitReplyTimer at " << Simulator::Now ().GetSeconds () << " due to ArpCache flush"); + m_waitReplyTimer.Cancel (); + } m_device = 0; m_interface = 0; if (!m_waitReplyTimer.IsRunning ()) @@ -241,11 +250,22 @@ ArpCache::Flush (void) { NS_LOG_FUNCTION (this); + std::vector keysToErase; + // First delete the entry for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) { - delete (*i).second; + if (!(*i).second->IsPermanent ()) + { + delete (*i).second; + keysToErase.push_back ((*i).first); + } } - m_arpCache.erase (m_arpCache.begin (), m_arpCache.end ()); + // Now erase the entries from the cache. Doing it outside of the above + // for loop since erasing invalidates the iterator + for(std::vector::size_type i = 0; i != keysToErase.size(); i++) + { + m_arpCache.erase (keysToErase[i]); + } if (m_waitReplyTimer.IsRunning ()) { NS_LOG_LOGIC ("Stopping WaitReplyTimer at " << Simulator::Now ().GetSeconds () << " due to ArpCache flush"); @@ -388,7 +408,7 @@ void ArpCache::Entry::MarkPermanent (Address macAddress) { - NS_LOG_FUNCTION (this); + NS_LOG_FUNCTION (this << macAddress); m_macAddress = macAddress; m_state = PERMANENT; ClearRetries ();