From 0e6a1c52a9335727e5c29efdbc429a82e73f5226 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Mon, 12 Jul 2021 12:51:47 +0200 Subject: [PATCH] Check if the callback is null again after flush() The call to flush() may result in the _oldestCallback becoming a nullptr. For instance, the SslConnected class might report an ssl error. This causes the _oldestCallback to become null. --- include/amqpcpp/channelimpl.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/amqpcpp/channelimpl.h b/include/amqpcpp/channelimpl.h index 82bc927..4d01c0c 100644 --- a/include/amqpcpp/channelimpl.h +++ b/include/amqpcpp/channelimpl.h @@ -674,14 +674,17 @@ public: // flush the queue, which will send the next operation if the current operation was synchronous flush(); - - // we are going to call callbacks that could destruct the channel - Monitor monitor(this); // 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); + // call the callback auto next = cb->reportSuccess(std::forward(parameters)...);