From e3678943cb52c82d4cd1fa9d92f4e84c237b55a0 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Mon, 12 Jul 2021 14:23:43 +0200 Subject: [PATCH] Monitor earlier in case flush() calls reportError. --- include/amqpcpp/channelimpl.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/amqpcpp/channelimpl.h b/include/amqpcpp/channelimpl.h index 4d01c0c..aacec9f 100644 --- a/include/amqpcpp/channelimpl.h +++ b/include/amqpcpp/channelimpl.h @@ -672,18 +672,21 @@ public: // skip if there is no oldest callback 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 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 // the "reportSuccess" call, if the channel is destructed during the call) auto cb = _oldestCallback; // the call to flush might have caused the callback to have been invoked; check once more - if (!cb) return false; - - // we are going to call callbacks that could destruct the channel - Monitor monitor(this); + if (!cb) return true; // call the callback auto next = cb->reportSuccess(std::forward(parameters)...);