From 31e4a8596c050cac08be901493483e15909ab1a4 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 18 Apr 2020 16:50:14 +0200 Subject: [PATCH] The onFinalize() callback could be called more than once, which is not ok --- include/amqpcpp/deferred.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/amqpcpp/deferred.h b/include/amqpcpp/deferred.h index c68ff78..e9c88c5 100644 --- a/include/amqpcpp/deferred.h +++ b/include/amqpcpp/deferred.h @@ -290,12 +290,12 @@ public: */ Deferred &onFinalize(const FinalizeCallback &callback) { - // store callback - _finalizeCallback = callback; - // if the object is already in a failed state, we call the callback right away if (_failed) callback(); + // otherwise we store callback until it's time for the call + else _finalizeCallback = callback; + // allow chaining return *this; }