From 060e42a6dd1076ac6223d6d163d451d13bdd608c Mon Sep 17 00:00:00 2001 From: Peter Eisenlohr Date: Fri, 25 Mar 2022 16:08:50 +0100 Subject: [PATCH] don't call moved-from callbacks --- include/amqpcpp/channelimpl.h | 2 +- include/amqpcpp/deferred.h | 2 +- src/channelimpl.cpp | 14 +++++++------- src/tagger.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/amqpcpp/channelimpl.h b/include/amqpcpp/channelimpl.h index de9f281..c487808 100644 --- a/include/amqpcpp/channelimpl.h +++ b/include/amqpcpp/channelimpl.h @@ -219,7 +219,7 @@ public: _readyCallback = std::move(callback); // direct call if channel is already ready - if (_state == state_ready && callback) callback(); + if (_state == state_ready && _readyCallback) _readyCallback(); } /** diff --git a/include/amqpcpp/deferred.h b/include/amqpcpp/deferred.h index a82ba84..03a5d5c 100644 --- a/include/amqpcpp/deferred.h +++ b/include/amqpcpp/deferred.h @@ -270,7 +270,7 @@ public: _errorCallback = std::move(callback); // if the object is already in a failed state, we call the callback right away - if (_failed) callback("Frame could not be sent"); + if (_failed) _errorCallback("Frame could not be sent"); // allow chaining return *this; diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index 1788fe1..086da31 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -74,25 +74,25 @@ void ChannelImpl::onError(ErrorCallback&& callback) if (usable()) return; // validity check - if (!callback) return; + if (!_errorCallback) return; // is the channel closing down? - if (_state == state_closing) return callback("Channel is closing down"); + if (_state == state_closing) return _errorCallback("Channel is closing down"); // the channel is closed, but what is the connection doing? - if (_connection == nullptr) return callback("Channel is not linked to a connection"); + if (_connection == nullptr) return _errorCallback("Channel is not linked to a connection"); // if the connection is valid, this is a pure channel error - if (_connection->ready()) return callback("Channel is in an error state, but the connection is valid"); + if (_connection->ready()) return _errorCallback("Channel is in an error state, but the connection is valid"); // the connection is closing down - if (_connection->closing()) return callback("Channel is in an error state, the AMQP connection is closing down"); + if (_connection->closing()) return _errorCallback("Channel is in an error state, the AMQP connection is closing down"); // the connection is already closed - if (_connection->closed()) return callback("Channel is in an error state, the AMQP connection has been closed"); + if (_connection->closed()) return _errorCallback("Channel is in an error state, the AMQP connection has been closed"); // direct call if channel is already in error state - callback("Channel is in error state, something went wrong with the AMQP connection"); + _errorCallback("Channel is in error state, something went wrong with the AMQP connection"); } /** diff --git a/src/tagger.cpp b/src/tagger.cpp index 29e4a31..03f38e0 100644 --- a/src/tagger.cpp +++ b/src/tagger.cpp @@ -188,13 +188,13 @@ void Tagger::onError(ErrorCallback&& callback) _errorCallback = std::move(callback); // check the callback - if (!callback) return; + if (!_errorCallback) return; // if the channel is no longer usable, report that - if (!_implementation->usable()) return callback("Channel is no longer usable"); + if (!_implementation->usable()) return _errorCallback("Channel is no longer usable"); // specify that we're already closing - if (_close) callback("Wrapped channel is closing down"); + if (_close) _errorCallback("Wrapped channel is closing down"); } /**