Opened 9 years ago

Closed 9 years ago

#9151 closed Bugs (wontfix)

memory leak in boost coroutines

Reported by: extproxy@… Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

Please see the attached program coro.cc. When I compile and run this with the heapchecker that comes with google-perftools, it reports a memory leak. Here's how to compile and run the program to reproduce the issue on Ubuntu 13.04:

$ sudo apt-get install libgoogle-perftools-dev

$ sudo apt-get install libboost1.53-all-dev

$ g++ -std=c++0x coro.cc -o coro -lboost_context -ltcmalloc

$ PPROF_PATH=/usr/bin/pprof HEAPCHECK=normal ./coro

The above reports the leaks as follows:

Leak of 152 bytes in 1 objects allocated from:

@ 413c78 gnu_cxx::new_allocator::allocate @ 413154 boost::coroutines::coroutine::coroutine @ 411586 boost::coroutines::detail::coroutine_object::run @ 40f713 boost::coroutines::detail::trampoline2 @ 7f01e9a5d76e make_fcontext

Attachments (2)

coro.cc (576 bytes ) - added by extproxy@… 9 years ago.
coro.cc
coro_mod.cc (1005 bytes ) - added by extproxy@… 9 years ago.

Download all attachments as: .zip

Change History (7)

by extproxy@…, 9 years ago

Attachment: coro.cc added

coro.cc

comment:1 by anonymous, 9 years ago

Component: Nonecoroutine
Owner: set to olli

comment:2 by olli, 9 years ago

Resolution: invalid
Status: newclosed

boost.coroutine creates an instance of a coroutine passed as argument to the coro-fn at the new stack stack. This coroutine instance will be destructed only if the stack is unwound. Unwinding is triggered only at destruction. Probably your profiling tool is not aware of this fact. You could take a look at example unwind.cpp which demonstrates that objects allocated on the coroutine stack will be deallocated (you could also add a destructor for push_coroutine which prints soem output if called - and you will see that this destructor will be called).

by extproxy@…, 9 years ago

Attachment: coro_mod.cc added

comment:3 by extproxy@…, 9 years ago

I've modified my program to use custom new/delete operators that print out every allocation and deallocation. The modified program is attached as coro_mod.cc.

It prints the following:

Allocated: 0x9e8010 Allocated: 0x9e8050 Allocated: 0x9e8070 Allocated: 0x9e80b0 Starting main Allocated: 0x9e80d0 Allocated: 0x9e80f0 Allocated: 0x9e81a0 In Hello 6 In Run1 In Hello end 4 In Hello end 5 In Run2 Freeing: 0x9e80f0 Freeing: 0x9e80d0 Finished main Freeing: 0x9e8070 Freeing: 0x9e80b0 Freeing: 0x9e8010 Freeing: 0x9e8050

Notice how there is one more allocation than free.

I compiled it as: g++ -std=c++0x coro_mod.cc -o coro_mod -lboost_context

comment:4 by extproxy@…, 9 years ago

Resolution: invalid
Status: closedreopened

comment:5 by olli, 9 years ago

Resolution: wontfix
Status: reopenedclosed

I see that you are using the old/deprecated interface (signature as template arg) of boost.coroutine.

I tried your code with the version in trunk (will be 1.55) and the count of allocations and de-allocations were equal. This means that the old code might contain a memory leak but because this code will be removed from boost.coroutine I won't fix it.

Note: See TracTickets for help on using tickets.