fix bug 431 -- memory leak in bridge net device
authorCraig Dowell <craigdo@ee.washington.edu>
Wed, 03 Dec 2008 17:47:03 -0800
changeset 3974 66afcfdff6a7
parent 3973 fce227ad1f13
child 3975 7a636112d9cd
fix bug 431 -- memory leak in bridge net device
examples/wifi-wired-bridging.cc
src/devices/bridge/bridge-net-device.cc
src/devices/bridge/bridge-net-device.h
--- a/examples/wifi-wired-bridging.cc	Tue Dec 02 12:15:42 2008 -0800
+++ b/examples/wifi-wired-bridging.cc	Wed Dec 03 17:47:03 2008 -0800
@@ -14,6 +14,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+//
 // Default network topology includes some number of AP nodes specified by
 // the variable nWifis (defaults to two).  Off of each AP node, there are some
 // number of STA nodes specified by the variable nStas (defaults to two).
@@ -176,6 +177,7 @@
       dest = tmp;
       protocol = "ns3::PacketSocketFactory";
     }
+
   OnOffHelper onoff = OnOffHelper (protocol, dest);
   onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
@@ -183,11 +185,10 @@
   apps.Start (Seconds (0.5));
   apps.Stop (Seconds (3.0));
   
-
-  YansWifiPhyHelper::EnablePcap ("wifi-wire-bridging", staNodes[1].Get (1));
-  YansWifiPhyHelper::EnablePcap ("wifi-wire-bridging", staNodes[0].Get (0));
+  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging", staNodes[1].Get (1));
+  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging", staNodes[0].Get (0));
   std::ofstream os;
-  os.open ("wifi-wire-bridging.mob");
+  os.open ("wifi-wired-bridging.mob");
   MobilityHelper::EnableAsciiAll (os);
 
   Simulator::Stop (Seconds (100.0));
--- a/src/devices/bridge/bridge-net-device.cc	Tue Dec 02 12:15:42 2008 -0800
+++ b/src/devices/bridge/bridge-net-device.cc	Wed Dec 03 17:47:03 2008 -0800
@@ -61,6 +61,25 @@
   m_channel = CreateObject<BridgeChannel> ();
 }
 
+BridgeNetDevice::~BridgeNetDevice()
+{
+  NS_LOG_FUNCTION_NOARGS ();
+}
+
+  void 
+BridgeNetDevice::DoDispose ()
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin (); iter != m_ports.end (); iter++)
+    {
+      *iter = 0;
+    }
+  m_ports.clear ();
+  m_channel = 0;
+  m_node = 0;
+  NetDevice::DoDispose ();
+}
+
 void
 BridgeNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol,
                                     Address const &src, Address const &dst, PacketType packetType)
@@ -421,14 +440,6 @@
   return true;
 }
 
-void
-BridgeNetDevice::DoDispose (void)
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  m_node = 0;
-  NetDevice::DoDispose ();
-}
-
 Address BridgeNetDevice::GetMulticast (Ipv6Address addr) const
 {
   NS_LOG_FUNCTION (this << addr);
--- a/src/devices/bridge/bridge-net-device.h	Tue Dec 02 12:15:42 2008 -0800
+++ b/src/devices/bridge/bridge-net-device.h	Wed Dec 03 17:47:03 2008 -0800
@@ -68,6 +68,7 @@
 public:
   static TypeId GetTypeId (void);
   BridgeNetDevice ();
+  virtual ~BridgeNetDevice ();
 
   /** \brief Add a 'port' to a bridge device
    *