Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in condition variable timed wait #162

savinz opened this issue Dec 25, 2017 · 3 comments


Copy link

commented Dec 25, 2017


the following test results in a memory leak (tested with valgrind, boost 1.66.0, gcc 6.3.0, linux x64):

#include <boost/fiber/all.hpp>                                                                                                              
#include <chrono>
using namespace std::chrono_literals;                                           
using namespace boost;                                                          
fibers::mutex mtx;                                                              
fibers::condition_variable cv;                                                  
void test() {                                                                               
        std::unique_lock<fibers::mutex> lock(mtx);                              
        //fibers::async([]{ cv.notify_one(); });                                
        cv.wait_for(lock, 1s);                                                  

The issue seems to be in missing intrusive_ptr_release (context) in case (cv) wait_for time-out.
No memory is leaked if wait_for completes without time-out. Other synchronization objects
have the same issue.

olk added a commit that referenced this issue Dec 27, 2017
- in context of #162

This comment has been minimized.

Copy link

commented Dec 27, 2017



This comment has been minimized.

Copy link

commented Mar 25, 2018

remove use-coutner increment for timed wait ops.

s/increment/decrement/ ?

intrusive_ptr_release method calls std::atomic::fetch_sub

friend void intrusive_ptr_release( algorithm * algo) noexcept {
BOOST_ASSERT( nullptr != algo);
if ( 1 == algo->use_count_.fetch_sub( 1, std::memory_order_release) ) {
std::atomic_thread_fence( std::memory_order_acquire);
delete algo;


This comment has been minimized.

Copy link

commented Mar 25, 2018

intrusive_ptr_release() is already contained in algorithm.hpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.