buffered_channel with range-for syntax leaks
dmitryikh opened this issue · 3 comments
dmitryikh commented
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.
dmitryikh commented
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;
}
}
olk commented
Could you test the fix please?
olk commented
no repsonse