Bug 2735 - Memory leakage due to pointer not deleted
Memory leakage due to pointer not deleted
Status: RESOLVED WONTFIX
Product: ns-3
Classification: Unclassified
Component: network
ns-3.26
All All
: P3 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-05-04 12:42 UTC by Menglei Zhang
Modified: 2018-07-26 11:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.