Bug 2735

Summary: Memory leakage due to pointer not deleted
Product: ns-3 Reporter: Menglei Zhang <mengleizhang.mz>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: RESOLVED WONTFIX    
Severity: normal CC: krotov, tomh
Priority: P3    
Version: ns-3.26   
Hardware: All   
OS: All   

Description Menglei Zhang 2017-05-04 12:42:00 UTC
In the methods Buffer::AddAtStart and Buffer::AddAtEnd, the newData pointer, created by the following command, is not deleted and cause memory leakage.
      struct Buffer::Data *newData = Buffer::Create (newSize); 
It can be fixed by changing the newData to a member variable, or use a smart pointer.
Comment 1 Tom Henderson 2017-05-04 13:33:30 UTC
Can you provide a test case we can use to test this?  We do not see memory error reports when we used valgrind on the ns-3 regression test suite.
Comment 2 Menglei Zhang 2017-05-04 14:41:55 UTC
My suggestion is to use smart pointer for the newData variable, and avoid the c style code.
Comment 3 Tom Henderson 2017-05-04 14:54:50 UTC
I am not convinced there is a problem.  Please provide a test program that exhibits a memory leak.
Comment 4 Alexander Krotov 2018-07-26 11:18:10 UTC
newData is not leaked because it is stored in m_data member.

Previous m_data is recycled if its reference counter reaches 0:
https://code.nsnam.org/index.cgi/ns-3-dev/file/f868c87528b1/src/network/model/buffer.cc#l334

There is a reference counter system already in place, it is just implemented manually. C++ "smart" pointers are not used because they have additional overhead (such as synchronization to make their modification atomic) which is avoided by implementing only the required parts in C.

Closing it with WONTFIX, can be reopened if the test case is provided.