From 52e3db279ab9ff348456234b8a033e703c6f7580 Mon Sep 17 00:00:00 2001 From: Elias Ohm Date: Wed, 17 Apr 2019 22:31:42 +0200 Subject: [PATCH] Fix for double-free (and possibly other memory-corruption related) crashes at logrotate time this is a direct fix of the issue revealing the problem that leads to crash verification done with a patched icinga2 where the execution-order of the code lines of counter-parts involved in re-incrementing/decrementing Timer:Ptr is forced to be the one that leads to the obeserverd segfaults refs #6737 --- lib/base/timer.cpp | 6 ++---- lib/base/timer.hpp | 2 +- test/base-timer.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 65a5d688b..ff00e79aa 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -110,7 +110,7 @@ void Timer::UninitializeThread() void Timer::Call() { try { - OnTimerExpired(Timer::Ptr(this)); + OnTimerExpired(this); } catch (...) { InternalReschedule(true); @@ -301,8 +301,6 @@ void Timer::TimerThreadProc() continue; } - Timer::Ptr ptimer = timer; - /* Remove the timer from the list so it doesn't get called again * until the current call is completed. */ l_Timers.erase(timer); @@ -312,6 +310,6 @@ void Timer::TimerThreadProc() lock.unlock(); /* Asynchronously call the timer. */ - Utility::QueueAsyncCallback(std::bind(&Timer::Call, ptimer)); + Utility::QueueAsyncCallback(std::bind(&Timer::Call, timer)); } } diff --git a/lib/base/timer.hpp b/lib/base/timer.hpp index 24937b7d5..2088a6660 100644 --- a/lib/base/timer.hpp +++ b/lib/base/timer.hpp @@ -39,7 +39,7 @@ public: void Reschedule(double next = -1); double GetNext() const; - boost::signals2::signal OnTimerExpired; + boost::signals2::signal OnTimerExpired; private: double m_Interval{0}; /**< The interval of the timer. */ diff --git a/test/base-timer.cpp b/test/base-timer.cpp index db6922ebc..d3a4a0040 100644 --- a/test/base-timer.cpp +++ b/test/base-timer.cpp @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(interval) int counter = 0; -static void Callback(const Timer::Ptr&) +static void Callback(const Timer * const&) { counter++; } -- 2.40.0