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:
Oliver Kowalke
2020-09-30 07:41:26 +02:00
parent f84f1a6d94
commit e440623814
2 changed files with 10 additions and 4 deletions
+5 -2
View File
@@ -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 :
+5 -2
View File
@@ -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 :