Bug 781

Summary: valgrind error for TestSuite devices-mesh-dot11s-regression
Product: ns-3 Reporter: Tom Henderson <tomh>
Component: wifiAssignee: Faker Moatamri <faker.moatamri>
Status: RESOLVED FIXED    
Severity: normal CC: ahippo, craigdo, faker.moatamri, mathieu.lacage
Priority: P1    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: Patch to enable valgrind suppressions and suppress this error

Description Tom Henderson 2009-12-20 14:49:08 UTC
To reproduce:
./test.py --grind --html=test-valgrind-results.html 
produces this error on ns-regression:
VALGR: TestSuite devices-mesh-dot11s-regression
Comment 1 Andrey Mazo 2009-12-22 11:15:17 UTC
(In reply to comment #0)
> To reproduce:
> ./test.py --grind --html=test-valgrind-results.html 
> produces this error on ns-regression:
> VALGR: TestSuite devices-mesh-dot11s-regression

Managed to reproduce only on amd64 (ns-regression).
Ns revision 8c65da328ae9.
Comment 2 Mathieu Lacage 2010-01-07 08:12:19 UTC
Here is the relevant error:
==22571== Invalid read of size 8
==22571==    at 0x5A059DD: ns3::dot11s::HwmpProtocolMac::SendPreq(std::vector<ns3::dot11s::IePreq, std::allocator<ns3::dot11s::IePreq> >) (hwmp-protocol-mac.cc:246)
==22571==    by 0x5A06506: ns3::dot11s::HwmpProtocolMac::SendPreq(ns3::dot11s::IePreq) (hwmp-protocol-mac.cc:222)
==22571==    by 0x5A11F3F: ns3::dot11s::HwmpProtocol::ReceivePreq(ns3::dot11s::IePreq, ns3::Mac48Address, unsigned, ns3::Mac48Address, unsigned) (hwmp-protocol.cc:557)
==22571==    by 0x5A06E75: ns3::dot11s::HwmpProtocolMac::ReceiveAction(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const&) (hwmp-protocol-mac.cc:129)
==22571==    by 0x5A07D96: ns3::dot11s::HwmpProtocolMac::Receive(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const&) (hwmp-protocol-mac.cc:176)
==22571==    by 0x59CBCCD: ns3::MeshWifiInterfaceMac::Receive(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) (mesh-wifi-interface-mac.cc:619)
==22571==    by 0x59D811D: ns3::MemPtrCallbackImpl<ns3::MeshWifiInterfaceMac*, void (ns3::MeshWifiInterfaceMac::*)(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*), void, ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator()(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) (callback.h:226)
==22571==    by 0x587FFA3: ns3::Callback<void, ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator()(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) const (callback.h:413)
==22571==    by 0x58871A8: ns3::MacRxMiddle::Receive(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) (mac-rx-middle.cc:298)
==22571==    by 0x58BA961: ns3::MemPtrCallbackImpl<ns3::MacRxMiddle*, void (ns3::MacRxMiddle::*)(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*), void, ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator()(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) (callback.h:226)
==22571==    by 0x587FFA3: ns3::Callback<void, ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator()(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) const (callback.h:413)
==22571==    by 0x587AC49: ns3::MacLow::ReceiveOk(ns3::Ptr<ns3::Packet>, double, ns3::WifiMode, ns3::WifiPreamble) (mac-low.cc:698)
==22571==  Address 0x68aa718 is 0 bytes inside a block of size 6 alloc'd
==22571==    at 0x4A06D5C: operator new(unsigned long) (vg_replace_malloc.c:230)
==22571==    by 0x59FA23F: __gnu_cxx::new_allocator<ns3::Mac48Address>::allocate(unsigned long, void const*) (new_allocator.h:92)
==22571==    by 0x59FA26D: std::_Vector_base<ns3::Mac48Address, std::allocator<ns3::Mac48Address> >::_M_allocate(unsigned long) (stl_vector.h:144)
==22571==    by 0x5A1C206: ns3::Mac48Address* std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<ns3::Mac48Address const*, std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> > > >(unsigned long, __gnu_cxx::__normal_iterator<ns3::Mac48Address const*, std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> > >, __gnu_cxx::__normal_iterator<ns3::Mac48Address const*, std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> > >) (stl_vector.h:904)
==22571==    by 0x5A1C29F: std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> >::operator=(std::vector<ns3::Mac48Address, std::allocator<ns3::Mac48Address> > const&) (vector.tcc:152)
==22571==    by 0x5A0D7A3: ns3::dot11s::HwmpProtocol::GetPreqReceivers(unsigned) (hwmp-protocol.cc:842)
==22571==    by 0x5A059A4: ns3::dot11s::HwmpProtocolMac::SendPreq(std::vector<ns3::dot11s::IePreq, std::allocator<ns3::dot11s::IePreq> >) (hwmp-protocol-mac.cc:243)
==22571==    by 0x5A06506: ns3::dot11s::HwmpProtocolMac::SendPreq(ns3::dot11s::IePreq) (hwmp-protocol-mac.cc:222)
==22571==    by 0x5A11F3F: ns3::dot11s::HwmpProtocol::ReceivePreq(ns3::dot11s::IePreq, ns3::Mac48Address, unsigned, ns3::Mac48Address, unsigned) (hwmp-protocol.cc:557)
==22571==    by 0x5A06E75: ns3::dot11s::HwmpProtocolMac::ReceiveAction(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const&) (hwmp-protocol-mac.cc:129)
==22571==    by 0x5A07D96: ns3::dot11s::HwmpProtocolMac::Receive(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const&) (hwmp-protocol-mac.cc:176)
==22571==    by 0x59CBCCD: ns3::MeshWifiInterfaceMac::Receive(ns3::Ptr<ns3::Packet>, ns3::WifiMacHeader const*) (mesh-wifi-interface-mac.cc:619)

What this is saying is that we are reading 8 bytes while the vector buffer is only 6 bytes big. So, there is only one entry in the buffer (Mac48Address is 6 bytes big) but we read 2 extra bytes because the compiler is optimizing read accesses to the buffer to align on the native system integer size. 

That error should be suppressed and ignored.
Comment 3 Faker Moatamri 2010-01-07 08:23:44 UTC
We should tell valgrind to ignore this error, that's what you mean?
Comment 4 Mathieu Lacage 2010-01-07 08:25:20 UTC
(In reply to comment #3)
> We should tell valgrind to ignore this error, that's what you mean?

yes, I believe so.
Comment 5 Tom Henderson 2010-01-08 01:45:07 UTC
Upgrading to valgrind-3.5.0 did not clear this problem on this machine; unfortunately, added another one:

VALGR: TestSuite routing-aodv-regression

./waf --command-template="valgrind %s --basedir=`pwd` --suite=routing-aodv-regression" --run test-runner
Waf: Entering directory `/tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev/build'
Waf: Leaving directory `/tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (0.698s)
==21407== Memcheck, a memory error detector
==21407== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==21407== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==21407== Command: /tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev/build/debug/utils/test-runner --basedir=/tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev --suite=routing-aodv-regression
==21407== 
file=../src/common/pcap-writer.cc, line=110, abort on="m_writer->fail ()", msg="PcapWriter::Open(): m_writer->open(/aodv-chain-regression-test-0-0.pcap) failed"
==21407== Invalid write of size 4
==21407==    at 0x56558EE: ns3::PcapWriter::Open(std::string const&) (pcap-writer.cc:110)
==21407==    by 0x5B52F44: ns3::YansWifiPhyHelper::EnablePcap(std::string, unsigned int, unsigned int) (yans-wifi-helper.cc:239)
==21407==    by 0x5B536C9: ns3::YansWifiPhyHelper::EnablePcap(std::string, ns3::NetDeviceContainer) (yans-wifi-helper.cc:270)
==21407==    by 0x5B538E8: ns3::YansWifiPhyHelper::EnablePcap(std::string, ns3::NodeContainer) (yans-wifi-helper.cc:299)
==21407==    by 0x5B539BB: ns3::YansWifiPhyHelper::EnablePcapAll(std::string) (yans-wifi-helper.cc:305)
==21407==    by 0x5A05DBE: ns3::aodv::ChainRegressionTest::CreateDevices() (aodv-regression.cc:156)
==21407==    by 0x5A07204: ns3::aodv::ChainRegressionTest::DoRun() (aodv-regression.cc:91)
==21407==    by 0x54BF59F: ns3::TestCase::Run() (test.cc:152)
==21407==    by 0x54BFD3B: ns3::TestSuite::DoRun() (test.cc:684)
==21407==    by 0x54BF281: ns3::TestSuite::Run() (test.cc:459)
==21407==    by 0x4026A8: main (test-runner.cc:263)
==21407==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==21407== 
==21407== 
==21407== Process terminating with default action of signal 11 (SIGSEGV)
==21407==  Access not within mapped region at address 0x0
==21407==    at 0x56558EE: ns3::PcapWriter::Open(std::string const&) (pcap-writer.cc:110)
==21407==    by 0x5B52F44: ns3::YansWifiPhyHelper::EnablePcap(std::string, unsigned int, unsigned int) (yans-wifi-helper.cc:239)
==21407==    by 0x5B536C9: ns3::YansWifiPhyHelper::EnablePcap(std::string, ns3::NetDeviceContainer) (yans-wifi-helper.cc:270)
==21407==    by 0x5B538E8: ns3::YansWifiPhyHelper::EnablePcap(std::string, ns3::NodeContainer) (yans-wifi-helper.cc:299)
==21407==    by 0x5B539BB: ns3::YansWifiPhyHelper::EnablePcapAll(std::string) (yans-wifi-helper.cc:305)
==21407==    by 0x5A05DBE: ns3::aodv::ChainRegressionTest::CreateDevices() (aodv-regression.cc:156)
==21407==    by 0x5A07204: ns3::aodv::ChainRegressionTest::DoRun() (aodv-regression.cc:91)
==21407==    by 0x54BF59F: ns3::TestCase::Run() (test.cc:152)
==21407==    by 0x54BFD3B: ns3::TestSuite::DoRun() (test.cc:684)
==21407==    by 0x54BF281: ns3::TestSuite::Run() (test.cc:459)
==21407==    by 0x4026A8: main (test-runner.cc:263)
==21407==  If you believe this happened as a result of a stack
==21407==  overflow in your program's main thread (unlikely but
==21407==  possible), you can try to increase the size of the
==21407==  main thread stack using the --main-stacksize= flag.
==21407==  The main thread stack size used in this run was 8388608.
==21407== 
==21407== HEAP SUMMARY:
==21407==     in use at exit: 378,233 bytes in 6,899 blocks
==21407==   total heap usage: 8,422 allocs, 1,523 frees, 491,765 bytes allocated
==21407== 
==21407== LEAK SUMMARY:
==21407==    definitely lost: 0 bytes in 0 blocks
==21407==    indirectly lost: 0 bytes in 0 blocks
==21407==      possibly lost: 127,923 bytes in 2,773 blocks
==21407==    still reachable: 250,310 bytes in 4,126 blocks
==21407==         suppressed: 0 bytes in 0 blocks
==21407== Rerun with --leak-check=full to see details of leaked memory
==21407== 
==21407== For counts of detected and suppressed errors, rerun with: -v
==21407== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 3 from 3)
Command ['valgrind', '/tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev/build/debug/utils/test-runner', '--basedir=/tmp/ns-commits/tests/tmp/ns-3-allinone/ns-3-dev', '--suite=routing-aodv-regression'] exited with code -11
Comment 6 Tom Henderson 2010-01-08 01:46:10 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > We should tell valgrind to ignore this error, that's what you mean?
> 
> yes, I believe so.

I can try to generate a suppressions file; should it be included in the source tree?
Comment 7 Faker Moatamri 2010-01-10 11:21:27 UTC
I think that it's a good idea to maintain the suppressions file since this type of errors are not going to disappear by magic and it is easier for the user to have the file included in the distribution. Moreover, more and more machines are 64 bits machine, so the error will happen more and more often.
+1 for maintaining a suppressions file.
Comment 8 Craig Dowell 2010-01-12 18:23:38 UTC
Created attachment 719 [details]
Patch to enable valgrind suppressions and suppress this error
Comment 9 Craig Dowell 2010-01-12 18:27:58 UTC
Faker, you can commit the patch if you approve.
Comment 10 Faker Moatamri 2010-01-13 04:34:52 UTC
Changeset: 766442c7f240, the error has been suppressed using a suppression file.