boostorg / fiber

userland threads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

buffered_channel with range-for syntax leaks

dmitryikh opened this issue · comments

I'm storing std::shared_ptr inside buffered_channel:

using DataSPtr = std::shared_ptr<const Msg>;
using Channel = boost::fibers::buffered_channel<DataSPtr>;

Then using range-for loop to consume values:

Channel ch(1024);
...
for (const auto msgSPtr : ch)
{
...
}

This code leads to constantly memory leaks. The workaround with while(true) & pop_value works just fine.

It seems that increment_() never calls value's destructors:

boost\fiber\buffered_channel.hpp:

        void increment_() {
            BOOST_ASSERT( nullptr != chan_);
            try {
                ::new ( static_cast< void * >( std::addressof( storage_) ) ) value_type{ chan_->value_pop() };
            } catch ( fiber_error const&) {
                chan_ = nullptr;
            }
        }

Could you test the fix please?

no repsonse