mirror of
https://github.com/boostorg/fiber.git
synced 2026-07-21 13:13:32 +00:00
buffered_channel with range-for syntax leaks #258
- call destructor before take new value from channel via placement new - skip calling desturctorfor the frist call of increment_()
This commit is contained in:
@@ -547,9 +547,12 @@ public:
|
||||
buffered_channel * chan_{ nullptr };
|
||||
storage_type storage_;
|
||||
|
||||
void increment_() {
|
||||
void increment_( bool initial = false) {
|
||||
BOOST_ASSERT( nullptr != chan_);
|
||||
try {
|
||||
if ( ! initial) {
|
||||
reinterpret_cast< value_type * >( std::addressof( storage_) )->~value_type();
|
||||
}
|
||||
::new ( static_cast< void * >( std::addressof( storage_) ) ) value_type{ chan_->value_pop() };
|
||||
} catch ( fiber_error const&) {
|
||||
chan_ = nullptr;
|
||||
@@ -569,7 +572,7 @@ public:
|
||||
|
||||
explicit iterator( buffered_channel< T > * chan) noexcept :
|
||||
chan_{ chan } {
|
||||
increment_();
|
||||
increment_( true);
|
||||
}
|
||||
|
||||
iterator( iterator const& other) noexcept :
|
||||
|
||||
@@ -577,9 +577,12 @@ public:
|
||||
unbuffered_channel * chan_{ nullptr };
|
||||
storage_type storage_;
|
||||
|
||||
void increment_() {
|
||||
void increment_( bool initial = false) {
|
||||
BOOST_ASSERT( nullptr != chan_);
|
||||
try {
|
||||
if ( ! initial) {
|
||||
reinterpret_cast< value_type * >( std::addressof( storage_) )->~value_type();
|
||||
}
|
||||
::new ( static_cast< void * >( std::addressof( storage_) ) ) value_type{ chan_->value_pop() };
|
||||
} catch ( fiber_error const&) {
|
||||
chan_ = nullptr;
|
||||
@@ -599,7 +602,7 @@ public:
|
||||
|
||||
explicit iterator( unbuffered_channel< T > * chan) noexcept :
|
||||
chan_{ chan } {
|
||||
increment_();
|
||||
increment_( true);
|
||||
}
|
||||
|
||||
iterator( iterator const& other) noexcept :
|
||||
|
||||
Reference in New Issue
Block a user