From b86c706b6bc4469d4aaa4740c2f4834c5be470ba Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Thu, 24 Sep 2009 18:05:36 -0400 Subject: [PATCH] PacketBB: Tidy up some memory leaks. --- src/node/packetbb-test-suite.cc | 5 +-- src/node/packetbb.cc | 60 +++++++++++++++++++++++++++++---- src/node/packetbb.h | 8 +++++ 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/node/packetbb-test-suite.cc b/src/node/packetbb-test-suite.cc index 80fbfe188..87b39138f 100644 --- a/src/node/packetbb-test-suite.cc +++ b/src/node/packetbb-test-suite.cc @@ -25,7 +25,7 @@ #include "ns3/ptr.h" #include "ns3/ipv4-address.h" #include "ns3/ipv6-address.h" -#include "packetbb.h" +#include "ns3/packetbb.h" using namespace ns3; @@ -34,7 +34,7 @@ class PbbTestCase : public TestCase public: PbbTestCase (std::string name, Ptr packet, uint8_t * buffer, uint32_t size); - virtual ~PbbTestCase (); + virtual ~PbbTestCase (void); protected: virtual bool DoRun (void); @@ -59,6 +59,7 @@ PbbTestCase::PbbTestCase (std::string name, Ptr packet, PbbTestCase::~PbbTestCase (void) { + return; } bool diff --git a/src/node/packetbb.cc b/src/node/packetbb.cc index 1060c7d2d..27292f253 100644 --- a/src/node/packetbb.cc +++ b/src/node/packetbb.cc @@ -58,6 +58,16 @@ namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (PbbPacket); +PbbTlvBlock::PbbTlvBlock (void) +{ + return; +} + +PbbTlvBlock::~PbbTlvBlock (void) +{ + Clear (); +} + PbbTlvBlock::Iterator PbbTlvBlock::Begin (void) { @@ -151,6 +161,10 @@ PbbTlvBlock::Erase (PbbTlvBlock::Iterator first, PbbTlvBlock::Iterator last) void PbbTlvBlock::Clear (void) { + for (Iterator iter = Begin (); iter != End (); iter++) + { + *iter = 0; + } m_tlvList.clear (); } @@ -262,6 +276,16 @@ PbbTlvBlock::operator!= (const PbbTlvBlock &other) const /* End PbbTlvBlock class */ +PbbAddressTlvBlock::PbbAddressTlvBlock (void) +{ + return; +} + +PbbAddressTlvBlock::~PbbAddressTlvBlock (void) +{ + Clear (); +} + PbbAddressTlvBlock::Iterator PbbAddressTlvBlock::Begin (void) { @@ -355,6 +379,10 @@ PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator first, PbbAddressTlvBloc void PbbAddressTlvBlock::Clear (void) { + for (Iterator iter = Begin (); iter != End (); iter++) + { + *iter = 0; + } m_tlvList.clear (); } @@ -474,6 +502,11 @@ PbbPacket::PbbPacket (void) m_hasseqnum = false; } +PbbPacket::~PbbPacket (void) +{ + MessageClear (); +} + uint8_t PbbPacket::GetVersion (void) const { @@ -706,6 +739,10 @@ PbbPacket::Erase (PbbPacket::MessageIterator first, void PbbPacket::MessageClear (void) { + for (MessageIterator iter = MessageBegin (); iter != MessageEnd (); iter++) + { + *iter = 0; + } m_messageList.clear (); } @@ -921,6 +958,7 @@ PbbMessage::PbbMessage () PbbMessage::~PbbMessage () { + AddressBlockClear (); } void @@ -1122,7 +1160,7 @@ PbbMessage::TlvErase (PbbMessage::TlvIterator first, PbbMessage::TlvIterator las void PbbMessage::TlvClear (void) { - return m_tlvList.Clear(); + m_tlvList.Clear(); } /* Manipulating Address Block and Address TLV pairs */ @@ -1227,6 +1265,12 @@ PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator first, void PbbMessage::AddressBlockClear (void) { + for (AddressBlockIterator iter = AddressBlockBegin (); + iter != AddressBlockEnd (); + iter++) + { + *iter = 0; + } return m_addressBlockList.clear(); } @@ -1956,7 +2000,7 @@ PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator first, void PbbAddressBlock::TlvClear (void) { - return m_addressTlvList.Clear(); + m_addressTlvList.Clear(); } void @@ -2412,6 +2456,11 @@ PbbTlv::PbbTlv (void) m_hasValue = false; } +PbbTlv::~PbbTlv (void) +{ + m_value.RemoveAtEnd (m_value.GetSize ()); +} + void PbbTlv::SetType (uint8_t type) { @@ -2506,10 +2555,9 @@ PbbTlv::SetValue (Buffer start) void PbbTlv::SetValue (const uint8_t * buffer, uint32_t size) { - Buffer value; - value.AddAtStart (size); - value.Begin ().Write (buffer, size); - SetValue (value); + m_hasValue = true; + m_value.AddAtStart (size); + m_value.Begin ().Write (buffer, size); } Buffer diff --git a/src/node/packetbb.h b/src/node/packetbb.h index 58194e534..1ee3014dc 100644 --- a/src/node/packetbb.h +++ b/src/node/packetbb.h @@ -57,6 +57,9 @@ public: typedef std::list< Ptr >::iterator Iterator; typedef std::list< Ptr >::const_iterator ConstIterator; + PbbTlvBlock (void); + ~PbbTlvBlock (void); + /** * \return an iterator to the first TLV in this block. */ @@ -206,6 +209,9 @@ public: typedef std::list< Ptr >::iterator Iterator; typedef std::list< Ptr >::const_iterator ConstIterator; + PbbAddressTlvBlock (void); + ~PbbAddressTlvBlock (void); + /** * \return an iterator to the first Address TLV in this block. */ @@ -363,6 +369,7 @@ public: typedef std::list< Ptr >::const_iterator ConstMessageIterator; PbbPacket (void); + ~PbbPacket (void); /** * \return the version of PacketBB that constructed this packet. @@ -1517,6 +1524,7 @@ class PbbTlv { public: PbbTlv (void); + ~PbbTlv (void); /** * \brief Sets the type of this TLV.