Boost C++ Libraries: Ticket #9151: memory leak in boost coroutines https://svn.boost.org/trac10/ticket/9151 <p> 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: </p> <p> $ sudo apt-get install libgoogle-perftools-dev </p> <p> $ sudo apt-get install libboost1.53-all-dev </p> <p> $ g++ -std=c++0x coro.cc -o coro -lboost_context -ltcmalloc </p> <p> $ PPROF_PATH=/usr/bin/pprof HEAPCHECK=normal ./coro </p> <p> The above reports the leaks as follows: </p> <p> Leak of 152 bytes in 1 objects allocated from: </p> <blockquote> <p> @ 413c78 <span class="underline">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 </span></p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9151 Trac 1.4.3 extproxy@… Mon, 23 Sep 2013 05:20:35 GMT attachment set https://svn.boost.org/trac10/ticket/9151 https://svn.boost.org/trac10/ticket/9151 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">coro.cc</span> </li> </ul> <p> coro.cc </p> Ticket anonymous Mon, 23 Sep 2013 05:23:56 GMT component changed; owner set https://svn.boost.org/trac10/ticket/9151#comment:1 https://svn.boost.org/trac10/ticket/9151#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">olli</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">coroutine</span> </li> </ul> Ticket olli Mon, 23 Sep 2013 07:49:20 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9151#comment:2 https://svn.boost.org/trac10/ticket/9151#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> 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). </p> Ticket extproxy@… Mon, 23 Sep 2013 15:27:45 GMT attachment set https://svn.boost.org/trac10/ticket/9151 https://svn.boost.org/trac10/ticket/9151 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">coro_mod.cc</span> </li> </ul> Ticket extproxy@… Mon, 23 Sep 2013 15:30:17 GMT <link>https://svn.boost.org/trac10/ticket/9151#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9151#comment:3</guid> <description> <p> 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. </p> <p> It prints the following: </p> <p> 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 </p> <p> Notice how there is one more allocation than free. </p> <p> I compiled it as: g++ -std=c++0x coro_mod.cc -o coro_mod -lboost_context </p> </description> <category>Ticket</category> </item> <item> <author>extproxy@…</author> <pubDate>Mon, 23 Sep 2013 15:31:36 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/9151#comment:4 https://svn.boost.org/trac10/ticket/9151#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> Ticket olli Mon, 23 Sep 2013 17:00:32 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9151#comment:5 https://svn.boost.org/trac10/ticket/9151#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> I see that you are using the old/deprecated interface (signature as template arg) of boost.coroutine.<br /> </p> <p> 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. </p> Ticket