avoid memory leaks
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 02 Mar 2008 06:43:12 +0100
changeset 253005f9cec44621
parent 2529 d5f8bee5fcbd
child 2531 b451b5fc8b57
avoid memory leaks
src/devices/wifi/adhoc-wifi-mac.cc
src/devices/wifi/adhoc-wifi-mac.h
src/devices/wifi/dca-txop.cc
src/devices/wifi/dca-txop.h
src/devices/wifi/mac-low.cc
src/devices/wifi/mac-low.h
src/devices/wifi/wifi-net-device.cc
src/devices/wifi/wifi-net-device.h
src/devices/wifi/wifi-phy.cc
src/devices/wifi/wifi-phy.h
src/devices/wifi/wifi-remote-station-manager.cc
src/devices/wifi/wifi-remote-station-manager.h
     1.1 --- a/src/devices/wifi/adhoc-wifi-mac.cc	Sun Mar 02 06:32:03 2008 +0100
     1.2 +++ b/src/devices/wifi/adhoc-wifi-mac.cc	Sun Mar 02 06:43:12 2008 +0100
     1.3 @@ -48,7 +48,7 @@
     1.4    m_rxMiddle = new MacRxMiddle ();
     1.5    m_rxMiddle->SetForwardCallback (MakeCallback (&AdhocWifiMac::ForwardUp, this));
     1.6  
     1.7 -  m_low = new MacLow ();
     1.8 +  m_low = CreateObjectWith<MacLow> ();
     1.9    m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
    1.10    m_low->SetMac (this);
    1.11  
    1.12 @@ -66,12 +66,13 @@
    1.13  AdhocWifiMac::DoDispose (void)
    1.14  {
    1.15    delete m_rxMiddle;
    1.16 -  delete m_low;
    1.17    delete m_dcfManager;
    1.18    m_rxMiddle = 0;
    1.19 +  m_dcfManager = 0;
    1.20    m_low = 0;
    1.21 -  m_dcfManager = 0;
    1.22    m_phy = 0;
    1.23 +  m_dca = 0;
    1.24 +  m_stationManager = 0;
    1.25    WifiMac::DoDispose ();
    1.26  }
    1.27  
     2.1 --- a/src/devices/wifi/adhoc-wifi-mac.h	Sun Mar 02 06:32:03 2008 +0100
     2.2 +++ b/src/devices/wifi/adhoc-wifi-mac.h	Sun Mar 02 06:43:12 2008 +0100
     2.3 @@ -79,7 +79,7 @@
     2.4    Ptr<WifiPhy> m_phy;
     2.5    DcfManager *m_dcfManager;
     2.6    MacRxMiddle *m_rxMiddle;
     2.7 -  MacLow *m_low;
     2.8 +  Ptr<MacLow> m_low;
     2.9    Mac48Address m_address;
    2.10    Ssid m_ssid;
    2.11  };
     3.1 --- a/src/devices/wifi/dca-txop.cc	Sun Mar 02 06:32:03 2008 +0100
     3.2 +++ b/src/devices/wifi/dca-txop.cc	Sun Mar 02 06:43:12 2008 +0100
     3.3 @@ -138,16 +138,22 @@
     3.4  }
     3.5  
     3.6  DcaTxop::~DcaTxop ()
     3.7 +{}
     3.8 +
     3.9 +void
    3.10 +DcaTxop::DoDispose (void)
    3.11  {
    3.12    delete m_transmissionListener;
    3.13    delete m_dcf;
    3.14    delete m_rng;
    3.15    delete m_txMiddle;
    3.16    m_transmissionListener = 0;
    3.17 -  m_queue = 0;
    3.18    m_dcf = 0;
    3.19    m_rng = 0;
    3.20    m_txMiddle = 0;
    3.21 +  m_queue = 0;
    3.22 +  m_low = 0;
    3.23 +  m_stationManager = 0;
    3.24  }
    3.25  
    3.26  void
     4.1 --- a/src/devices/wifi/dca-txop.h	Sun Mar 02 06:32:03 2008 +0100
     4.2 +++ b/src/devices/wifi/dca-txop.h	Sun Mar 02 06:43:12 2008 +0100
     4.3 @@ -144,6 +144,7 @@
     4.4    bool IsLastFragment (void);
     4.5    void NextFragment (void);
     4.6    Ptr<Packet> GetFragmentPacket (WifiMacHeader *hdr);
     4.7 +  virtual void DoDispose (void);
     4.8  
     4.9    Dcf *m_dcf;
    4.10    DcfManager *m_manager;
     5.1 --- a/src/devices/wifi/mac-low.cc	Sun Mar 02 06:32:03 2008 +0100
     5.2 +++ b/src/devices/wifi/mac-low.cc	Sun Mar 02 06:43:12 2008 +0100
     5.3 @@ -238,9 +238,15 @@
     5.4  }
     5.5  
     5.6  MacLow::~MacLow ()
     5.7 +{}
     5.8 +
     5.9 +void 
    5.10 +MacLow::DoDispose (void)
    5.11  {
    5.12    CancelAllEvents ();
    5.13    m_phy = 0;
    5.14 +  m_mac = 0;
    5.15 +  m_stationManager = 0;
    5.16  }
    5.17  
    5.18  void
     6.1 --- a/src/devices/wifi/mac-low.h	Sun Mar 02 06:32:03 2008 +0100
     6.2 +++ b/src/devices/wifi/mac-low.h	Sun Mar 02 06:43:12 2008 +0100
     6.3 @@ -382,6 +382,7 @@
     6.4    void SendDataPacket (void);
     6.5    void SendCurrentTxPacket (void);
     6.6    void StartDataTxTimers (void);
     6.7 +  virtual void DoDispose (void);
     6.8  
     6.9    Ptr<WifiPhy> m_phy;
    6.10    Ptr<WifiMac> m_mac;
     7.1 --- a/src/devices/wifi/wifi-net-device.cc	Sun Mar 02 06:32:03 2008 +0100
     7.2 +++ b/src/devices/wifi/wifi-net-device.cc	Sun Mar 02 06:43:12 2008 +0100
     7.3 @@ -47,6 +47,20 @@
     7.4  {}
     7.5  WifiNetDevice::~WifiNetDevice ()
     7.6  {}
     7.7 +
     7.8 +void
     7.9 +WifiNetDevice::DoDispose (void)
    7.10 +{
    7.11 +  m_node = 0;
    7.12 +  m_mac->Dispose ();
    7.13 +  m_phy->Dispose ();
    7.14 +  m_stationManager->Dispose ();
    7.15 +  m_mac = 0;
    7.16 +  m_phy = 0;
    7.17 +  m_stationManager = 0;
    7.18 +  // chain up.
    7.19 +  NetDevice::DoDispose ();
    7.20 +}
    7.21    
    7.22  void 
    7.23  WifiNetDevice::Setup (Ptr<Node> node, Ptr<WifiMac> mac, Ptr<WifiPhy> phy,
     8.1 --- a/src/devices/wifi/wifi-net-device.h	Sun Mar 02 06:32:03 2008 +0100
     8.2 +++ b/src/devices/wifi/wifi-net-device.h	Sun Mar 02 06:43:12 2008 +0100
     8.3 @@ -78,6 +78,7 @@
     8.4    virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
     8.5  
     8.6  private:
     8.7 +  virtual void DoDispose (void);
     8.8    void ForwardUp (Ptr<Packet> packet, const Mac48Address &from);
     8.9    void LinkUp (void);
    8.10    void LinkDown (void);
     9.1 --- a/src/devices/wifi/wifi-phy.cc	Sun Mar 02 06:32:03 2008 +0100
     9.2 +++ b/src/devices/wifi/wifi-phy.cc	Sun Mar 02 06:43:12 2008 +0100
     9.3 @@ -254,6 +254,10 @@
     9.4  {}
     9.5  
     9.6  WifiPhy::~WifiPhy ()
     9.7 +{}
     9.8 +
     9.9 +void
    9.10 +WifiPhy::DoDispose (void)
    9.11  {
    9.12    m_channel = 0;
    9.13    m_events.clear ();
    10.1 --- a/src/devices/wifi/wifi-phy.h	Sun Mar 02 06:32:03 2008 +0100
    10.2 +++ b/src/devices/wifi/wifi-phy.h	Sun Mar 02 06:43:12 2008 +0100
    10.3 @@ -266,6 +266,7 @@
    10.4    typedef std::vector <NiChange> NiChanges;
    10.5  
    10.6  private:
    10.7 +  virtual void DoDispose (void);
    10.8    void Configure80211aParameters (void);
    10.9    void PrintModes (void) const;
   10.10    void Configure80211a (void);
    11.1 --- a/src/devices/wifi/wifi-remote-station-manager.cc	Sun Mar 02 06:32:03 2008 +0100
    11.2 +++ b/src/devices/wifi/wifi-remote-station-manager.cc	Sun Mar 02 06:43:12 2008 +0100
    11.3 @@ -155,6 +155,10 @@
    11.4  
    11.5  WifiRemoteStationManager::~WifiRemoteStationManager ()
    11.6  {
    11.7 +}
    11.8 +void 
    11.9 +WifiRemoteStationManager::DoDispose (void)
   11.10 +{
   11.11    for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++) 
   11.12      {
   11.13        delete (*i).second;
    12.1 --- a/src/devices/wifi/wifi-remote-station-manager.h	Sun Mar 02 06:32:03 2008 +0100
    12.2 +++ b/src/devices/wifi/wifi-remote-station-manager.h	Sun Mar 02 06:43:12 2008 +0100
    12.3 @@ -76,6 +76,8 @@
    12.4  
    12.5    WifiRemoteStation *Lookup (Mac48Address address);
    12.6    WifiRemoteStation *LookupNonUnicast (void);
    12.7 +protected:
    12.8 +  virtual void DoDispose (void);
    12.9  private:
   12.10    typedef std::vector <std::pair<Mac48Address, WifiRemoteStation *> > Stations;
   12.11    virtual class WifiRemoteStation *CreateStation (void) = 0;