This is an automated email from the ASF dual-hosted git repository.

guangning pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit d00b09a7c0299c61712c16f94aec2d5756600681
Author: Matteo Merli <[email protected]>
AuthorDate: Sun Feb 9 21:43:14 2020 -0800

    [C++] Fixed handling of canceled timer events on NegativeAcksTracker (#6272)
    
    When handling a "timer cancelled" event, we cannot lock the mutex since the 
object itself might already be destroyed.
    
    This causes potentially a memory corruption/segfault.
---
 pulsar-client-cpp/lib/NegativeAcksTracker.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pulsar-client-cpp/lib/NegativeAcksTracker.cc 
b/pulsar-client-cpp/lib/NegativeAcksTracker.cc
index e307091..492e379 100644
--- a/pulsar-client-cpp/lib/NegativeAcksTracker.cc
+++ b/pulsar-client-cpp/lib/NegativeAcksTracker.cc
@@ -48,14 +48,14 @@ void NegativeAcksTracker::scheduleTimer() {
 }
 
 void NegativeAcksTracker::handleTimer(const boost::system::error_code &ec) {
-    std::lock_guard<std::mutex> lock(mutex_);
-    timer_ = nullptr;
-
     if (ec) {
         // Ignore cancelled events
         return;
     }
 
+    std::lock_guard<std::mutex> lock(mutex_);
+    timer_ = nullptr;
+
     if (nackedMessages_.empty()) {
         return;
     }

Reply via email to