Monitor earlier in case flush() calls reportError.

This commit is contained in:
Raoul Wols 2021-07-12 14:23:43 +02:00
parent ead7b7962e
commit e3678943cb
No known key found for this signature in database
GPG Key ID: 9FFE06A0F6AAA2DF
1 changed files with 7 additions and 4 deletions

View File

@ -672,18 +672,21 @@ public:
// skip if there is no oldest callback // skip if there is no oldest callback
if (!_oldestCallback) return true; if (!_oldestCallback) return true;
// we are going to call callbacks that could destruct the channel
Monitor monitor(this);
// flush the queue, which will send the next operation if the current operation was synchronous // flush the queue, which will send the next operation if the current operation was synchronous
flush(); flush();
// the call to flush may have resulted in a call to reportError
if (!monitor.valid()) return false;
// copy the callback (so that it will not be destructed during // copy the callback (so that it will not be destructed during
// the "reportSuccess" call, if the channel is destructed during the call) // the "reportSuccess" call, if the channel is destructed during the call)
auto cb = _oldestCallback; auto cb = _oldestCallback;
// the call to flush might have caused the callback to have been invoked; check once more // the call to flush might have caused the callback to have been invoked; check once more
if (!cb) return false; if (!cb) return true;
// we are going to call callbacks that could destruct the channel
Monitor monitor(this);
// call the callback // call the callback
auto next = cb->reportSuccess(std::forward<Arguments>(parameters)...); auto next = cb->reportSuccess(std::forward<Arguments>(parameters)...);