[C++] Fixed handling of canceled timer events on NegativeAcksTracker
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.
@@ -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;
}
