NetSys / bess

BESS: Berkeley Extensible Software Switch
Other
313 stars 156 forks source link

Memory leak in TrafficClass #193

Closed changlan closed 7 years ago

changlan commented 7 years ago

This is already known and discussed. Posting here so that we don't forget to fix it.

How to reproduce

make CXX=clang++ SANITIZE=1
./all_test

Error message:

vagrant@nefeli-vm:/bess/core$ ./all_test
[==========] Running 80 tests from 31 test cases.
[----------] Global test environment set-up.
[----------] 1 test from ProcessCommandLineArgs
[ RUN      ] ProcessCommandLineArgs.DumpTypes
gcc: 4.2.1
glibc: 2.23-stable
DPDK: DPDK 16.07.0
sizeof(char)=1
sizeof(short)=2
sizeof(int)=4
sizeof(long)=8
sizeof(long long)=8
sizeof(intmax_t)=8
sizeof(void *)=8
sizeof(size_t)=8
sizeof(HTableBase)=96
sizeof(rte_mbuf)=128
sizeof(Packet)=2560
sizeof(pkt_batch)=264
sizeof(Scheduler)=120 sizeof(sched_stats)=48
sizeof(TrafficClass)=96 sizeof(tc_stats)=40
sizeof(Task)=32
sizeof(Module)=168
sizeof(Gate)=48
sizeof(IGate)=72
sizeof(OGate)=64
sizeof(worker_context)=2163024
[       OK ] ProcessCommandLineArgs.DumpTypes (218 ms)
[----------] 1 test from ProcessCommandLineArgs (218 ms total)

[----------] 1 test from CheckRunningAsRoot
[ RUN      ] CheckRunningAsRoot.NonRoot
[       OK ] CheckRunningAsRoot.NonRoot (200 ms)
[----------] 1 test from CheckRunningAsRoot (200 ms total)

[----------] 1 test from WriteAndReadPidFile
[ RUN      ] WriteAndReadPidFile.GoodFile
[       OK ] WriteAndReadPidFile.GoodFile (4 ms)
[----------] 1 test from WriteAndReadPidFile (4 ms total)

[----------] 1 test from WritePidFile
[ RUN      ] WritePidFile.BadFile
[       OK ] WritePidFile.BadFile (679 ms)
[----------] 1 test from WritePidFile (679 ms total)

[----------] 2 tests from ReadPidFile
[ RUN      ] ReadPidFile.BadFileDesciptor
[       OK ] ReadPidFile.BadFileDesciptor (731 ms)
[ RUN      ] ReadPidFile.BadFile
E1216 20:03:37.815279  5574 bessd.cc:153] read(pidfile=/var/run/bessd.pid) at EOF
[       OK ] ReadPidFile.BadFile (2 ms)
[----------] 2 tests from ReadPidFile (733 ms total)

[----------] 4 tests from TryAcquirePidfileLock
[ RUN      ] TryAcquirePidfileLock.BadFd
[       OK ] TryAcquirePidfileLock.BadFd (706 ms)
[ RUN      ] TryAcquirePidfileLock.GoodFd
[       OK ] TryAcquirePidfileLock.GoodFd (0 ms)
[ RUN      ] TryAcquirePidfileLock.AlreadyHeld
[       OK ] TryAcquirePidfileLock.AlreadyHeld (58 ms)
[ RUN      ] TryAcquirePidfileLock.AlreadyHeldPidReadFails
[       OK ] TryAcquirePidfileLock.AlreadyHeldPidReadFails (2251 ms)
[----------] 4 tests from TryAcquirePidfileLock (3015 ms total)

[----------] 4 tests from CheckUniqueInstance
[ RUN      ] CheckUniqueInstance.BadPidfilePath
[       OK ] CheckUniqueInstance.BadPidfilePath (713 ms)
[ RUN      ] CheckUniqueInstance.NotHeld
[       OK ] CheckUniqueInstance.NotHeld (1 ms)
[ RUN      ] CheckUniqueInstance.Held
[       OK ] CheckUniqueInstance.Held (2340 ms)
[ RUN      ] CheckUniqueInstance.HeldKillCurrentHolder
[       OK ] CheckUniqueInstance.HeldKillCurrentHolder (1020 ms)
[----------] 4 tests from CheckUniqueInstance (4074 ms total)

[----------] 1 test from Daemonize
[ RUN      ] Daemonize.BasicRun
[       OK ] Daemonize.BasicRun (69 ms)
[----------] 1 test from Daemonize (70 ms total)

[----------] 1 test from SetResourceLimit
[ RUN      ] SetResourceLimit.BasicRun
[       OK ] SetResourceLimit.BasicRun (0 ms)
[----------] 1 test from SetResourceLimit (0 ms total)

[----------] 5 tests from CreateTree
[ RUN      ] CreateTree.Leaf
[       OK ] CreateTree.Leaf (1 ms)
[ RUN      ] CreateTree.PriorityRootAndLeaf
[       OK ] CreateTree.PriorityRootAndLeaf (1 ms)
[ RUN      ] CreateTree.WeightedFairRootAndLeaf
[       OK ] CreateTree.WeightedFairRootAndLeaf (2 ms)
[ RUN      ] CreateTree.RoundRobinRootAndLeaf
[       OK ] CreateTree.RoundRobinRootAndLeaf (1 ms)
[ RUN      ] CreateTree.RateLimitRootAndLeaf
[       OK ] CreateTree.RateLimitRootAndLeaf (1 ms)
[----------] 5 tests from CreateTree (8 ms total)

[----------] 5 tests from SchedulerNext
[ RUN      ] SchedulerNext.BasicTreePriority
[       OK ] SchedulerNext.BasicTreePriority (1 ms)
[ RUN      ] SchedulerNext.BasicTreeWeightedFair
[       OK ] SchedulerNext.BasicTreeWeightedFair (1 ms)
[ RUN      ] SchedulerNext.BasicTreeRoundRobin
[       OK ] SchedulerNext.BasicTreeRoundRobin (0 ms)
[ RUN      ] SchedulerNext.BasicTreeRateLimit
[       OK ] SchedulerNext.BasicTreeRateLimit (0 ms)
[ RUN      ] SchedulerNext.TwoLeavesWeightedFairOneBlocked
[       OK ] SchedulerNext.TwoLeavesWeightedFairOneBlocked (1 ms)
[----------] 5 tests from SchedulerNext (4 ms total)

[----------] 4 tests from ScheduleOnce
[ RUN      ] ScheduleOnce.TwoLeavesWeightedFair
[       OK ] ScheduleOnce.TwoLeavesWeightedFair (1 ms)
[ RUN      ] ScheduleOnce.TwoLeavesPriority
[       OK ] ScheduleOnce.TwoLeavesPriority (0 ms)
[ RUN      ] ScheduleOnce.TwoLeavesRoundRobin
[       OK ] ScheduleOnce.TwoLeavesRoundRobin (0 ms)
[ RUN      ] ScheduleOnce.LeavesWeightedFairAndRoundRobin
[       OK ] ScheduleOnce.LeavesWeightedFairAndRoundRobin (1 ms)
[----------] 4 tests from ScheduleOnce (5 ms total)

[----------] 1 test from RateLimit
[ RUN      ] RateLimit.BasicBlockUnblock
[       OK ] RateLimit.BasicBlockUnblock (2 ms)
[----------] 1 test from RateLimit (2 ms total)

[----------] 2 tests from ModuleBuilderTest
[ RUN      ] ModuleBuilderTest.RegisterModuleClass
[       OK ] ModuleBuilderTest.RegisterModuleClass (2 ms)
[ RUN      ] ModuleBuilderTest.GenerateDefaultNameTemplate
[       OK ] ModuleBuilderTest.GenerateDefaultNameTemplate (1 ms)
[----------] 2 tests from ModuleBuilderTest (4 ms total)

[----------] 5 tests from ModuleTester
[ RUN      ] ModuleTester.CreateModuleWithName
[       OK ] ModuleTester.CreateModuleWithName (5 ms)
[ RUN      ] ModuleTester.CreateModuleGenerateName
[       OK ] ModuleTester.CreateModuleGenerateName (0 ms)
[ RUN      ] ModuleTester.RunCommand
[       OK ] ModuleTester.RunCommand (1 ms)
[ RUN      ] ModuleTester.ConnectModules
[       OK ] ModuleTester.ConnectModules (2 ms)
[ RUN      ] ModuleTester.ResetModules
[       OK ] ModuleTester.ResetModules (1 ms)
[----------] 5 tests from ModuleTester (10 ms total)

[----------] 8 tests from PortTest
[ RUN      ] PortTest.CreatePort
[       OK ] PortTest.CreatePort (1 ms)
[ RUN      ] PortTest.AddPort
[       OK ] PortTest.AddPort (0 ms)
[ RUN      ] PortTest.GetPortStats
[       OK ] PortTest.GetPortStats (0 ms)
[ RUN      ] PortTest.AcquireAndReleaseQueues
E1216 20:03:45.014201  5574 port.cc:173] Incorrect packet dir 2
[       OK ] PortTest.AcquireAndReleaseQueues (1 ms)
[ RUN      ] PortTest.DestroyPort
[       OK ] PortTest.DestroyPort (0 ms)
[ RUN      ] PortTest.DestroyAllPorts
[       OK ] PortTest.DestroyAllPorts (0 ms)
[ RUN      ] PortTest.InitPortClass
[       OK ] PortTest.InitPortClass (0 ms)
[ RUN      ] PortTest.InitDrivers
[       OK ] PortTest.InitDrivers (0 ms)
[----------] 8 tests from PortTest (7 ms total)

[----------] 3 tests from PortBuilderTest
[ RUN      ] PortBuilderTest.RegisterPortClassDirectCall
[       OK ] PortBuilderTest.RegisterPortClassDirectCall (0 ms)
[ RUN      ] PortBuilderTest.RegisterPortClassMacroCall
[       OK ] PortBuilderTest.RegisterPortClassMacroCall (0 ms)
[ RUN      ] PortBuilderTest.GenerateDefaultPortNameTemplate
[       OK ] PortBuilderTest.GenerateDefaultPortNameTemplate (0 ms)
[----------] 3 tests from PortBuilderTest (2 ms total)

[----------] 2 tests from Metadata
[ RUN      ] Metadata.RegisterSizeMismatchFails
E1216 20:03:45.022128  5574 metadata.cc:471] Attribute 'attr0' has size mismatch: registered(1) vs new(2)
[       OK ] Metadata.RegisterSizeMismatchFails (2 ms)
[ RUN      ] Metadata.RegisterCount
E1216 20:03:45.023066  5574 metadata.cc:471] Attribute 'a' has size mismatch: registered(4) vs new(8)
E1216 20:03:45.023317  5574 metadata.cc:471] Attribute 'a' has size mismatch: registered(4) vs new(8)
E1216 20:03:45.023591  5574 metadata.cc:471] Attribute 'a' has size mismatch: registered(4) vs new(8)
[       OK ] Metadata.RegisterCount (1 ms)
[----------] 2 tests from Metadata (4 ms total)

[----------] 7 tests from MetadataTest
[ RUN      ] MetadataTest.DisconnectedFails
[       OK ] MetadataTest.DisconnectedFails (3 ms)
[ RUN      ] MetadataTest.SingleAttrSimplePipe
[       OK ] MetadataTest.SingleAttrSimplePipe (1 ms)
[ RUN      ] MetadataTest.SingleAttrSimplePipeBackwardsFails
[       OK ] MetadataTest.SingleAttrSimplePipeBackwardsFails (1 ms)
[ RUN      ] MetadataTest.MultipleAttrSimplePipeNoSpaceFails
[       OK ] MetadataTest.MultipleAttrSimplePipeNoSpaceFails (1 ms)
[ RUN      ] MetadataTest.MultipeAttrSimplePipe
[       OK ] MetadataTest.MultipeAttrSimplePipe (1 ms)
[ RUN      ] MetadataTest.MultipeAttrComplexPipe
[       OK ] MetadataTest.MultipeAttrComplexPipe (1 ms)
[ RUN      ] MetadataTest.ScopeComponentDegreeOrder
[       OK ] MetadataTest.ScopeComponentDegreeOrder (1 ms)
[----------] 7 tests from MetadataTest (9 ms total)

[----------] 4 tests from GateTest
[ RUN      ] GateTest.AddExistingHookFails
[       OK ] GateTest.AddExistingHookFails (0 ms)
[ RUN      ] GateTest.HookPriority
[       OK ] GateTest.HookPriority (0 ms)
[ RUN      ] GateTest.FindHook
[       OK ] GateTest.FindHook (0 ms)
[ RUN      ] GateTest.RemoveHook
[       OK ] GateTest.RemoveHook (0 ms)
[----------] 4 tests from GateTest (3 ms total)

[----------] 1 test from HookTest
[ RUN      ] HookTest.TrackGate
[       OK ] HookTest.TrackGate (0 ms)
[----------] 1 test from HookTest (0 ms total)

[----------] 2 tests from IOGateTest
[ RUN      ] IOGateTest.OGate
[       OK ] IOGateTest.OGate (0 ms)
[ RUN      ] IOGateTest.IGate
[       OK ] IOGateTest.IGate (0 ms)
[----------] 2 tests from IOGateTest (1 ms total)

[----------] 3 tests from EthHeaderTest
[ RUN      ] EthHeaderTest.AddressInStr
[       OK ] EthHeaderTest.AddressInStr (1 ms)
[ RUN      ] EthHeaderTest.AddrEquality
[       OK ] EthHeaderTest.AddrEquality (0 ms)
[ RUN      ] EthHeaderTest.RandomAddr
[       OK ] EthHeaderTest.RandomAddr (0 ms)
[----------] 3 tests from EthHeaderTest (3 ms total)

[----------] 2 tests from PcapHandleBasicTest
[ RUN      ] PcapHandleBasicTest.EmptyConstructor
[       OK ] PcapHandleBasicTest.EmptyConstructor (0 ms)
[ RUN      ] PcapHandleBasicTest.BadDevice
[       OK ] PcapHandleBasicTest.BadDevice (2 ms)
[----------] 2 tests from PcapHandleBasicTest (2 ms total)

[----------] 2 tests from PcapHandleFixtureTest
[ RUN      ] PcapHandleFixtureTest.MoveAssignment
[       OK ] PcapHandleFixtureTest.MoveAssignment (0 ms)
[ RUN      ] PcapHandleFixtureTest.MoveConstructor
[       OK ] PcapHandleFixtureTest.MoveConstructor (0 ms)
[----------] 2 tests from PcapHandleFixtureTest (0 ms total)

[----------] 1 test from RdtscTest
[ RUN      ] RdtscTest.NonDecreasing
[       OK ] RdtscTest.NonDecreasing (0 ms)
[----------] 1 test from RdtscTest (0 ms total)

[----------] 2 tests from TscToUs
[ RUN      ] TscToUs.Frequency
[       OK ] TscToUs.Frequency (0 ms)
[ RUN      ] TscToUs.NonNegative
[       OK ] TscToUs.NonNegative (0 ms)
[----------] 2 tests from TscToUs (0 ms total)

[----------] 1 test from GetEpochTime
[ RUN      ] GetEpochTime.NonNegative
[       OK ] GetEpochTime.NonNegative (0 ms)
[----------] 1 test from GetEpochTime (0 ms total)

[----------] 1 test from GetCpuTime
[ RUN      ] GetCpuTime.NonNegative
[       OK ] GetCpuTime.NonNegative (0 ms)
[----------] 1 test from GetCpuTime (0 ms total)

[----------] 1 test from RoundRobinTest
[ RUN      ] RoundRobinTest.PositiveGates
[       OK ] RoundRobinTest.PositiveGates (1 ms)
[----------] 1 test from RoundRobinTest (1 ms total)

[----------] 2 tests from ZeroCopyVPortTest
[ RUN      ] ZeroCopyVPortTest.Send
[       OK ] ZeroCopyVPortTest.Send (116 ms)
[ RUN      ] ZeroCopyVPortTest.Recv
[       OK ] ZeroCopyVPortTest.Recv (0 ms)
[----------] 2 tests from ZeroCopyVPortTest (118 ms total)

[----------] Global test environment tear-down
[==========] 80 tests from 31 test cases ran. (9182 ms total)
[  PASSED  ] 80 tests.

=================================================================
==5574==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 256 byte(s) in 2 object(s) allocated from:
    #0 0x6f8980 in operator new(unsigned long) (/bess/core/all_test+0x6f8980)
    #1 0x72c912 in bess::LeafTrafficClass* bess::TrafficClassBuilder::CreateTrafficClass<bess::LeafTrafficClass>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /bess/core/./traffic_class.h:514:12
    #2 0x72c912 in bess::TrafficClassBuilder::CreateTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bess::TrafficClassBuilder::LeafArgs) /bess/core/./traffic_class.h:623
changlan commented 7 years ago

Fixed by #199