]> granicus.if.org Git - icinga2/commitdiff
Fix for double-free (and possibly other memory-corruption related) crashes at logrota...
authorElias Ohm <eohm@novomind.com>
Wed, 17 Apr 2019 20:31:42 +0000 (22:31 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 16 May 2019 13:26:47 +0000 (15:26 +0200)
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

(cherry picked from commit 52e3db279ab9ff348456234b8a033e703c6f7580)

lib/base/timer.cpp
lib/base/timer.hpp
test/base-timer.cpp

index 2bcff3a4b7e122c809edd87660acba9e77250af2..8feae797155309a03f335e1c7037dfdf2274140b 100644 (file)
@@ -127,7 +127,7 @@ void Timer::UninitializeThread()
 void Timer::Call()
 {
        try {
-               OnTimerExpired(Timer::Ptr(this));
+               OnTimerExpired(this);
        } catch (...) {
                InternalReschedule(true);
 
@@ -318,8 +318,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);
@@ -329,6 +327,6 @@ void Timer::TimerThreadProc()
                lock.unlock();
 
                /* Asynchronously call the timer. */
-               Utility::QueueAsyncCallback(std::bind(&Timer::Call, ptimer));
+               Utility::QueueAsyncCallback(std::bind(&Timer::Call, timer));
        }
 }
index 96b77532262139b95bf45736e680e86075555152..7950faf372c6d86063f3fd036adef9b6f2ceb6bf 100644 (file)
@@ -56,7 +56,7 @@ public:
        void Reschedule(double next = -1);
        double GetNext() const;
 
-       boost::signals2::signal<void(const Timer::Ptr&)> OnTimerExpired;
+       boost::signals2::signal<void(const Timer * const&)> OnTimerExpired;
 
 private:
        double m_Interval{0}; /**< The interval of the timer. */
index a9500a2039aedcc4624eb7d1c1e126a0534f20bb..81b303ff05a6dcfdff138375482204d5f535f50e 100644 (file)
@@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(interval)
 
 int counter = 0;
 
-static void Callback(const Timer::Ptr&)
+static void Callback(const Timer * const&)
 {
        counter++;
 }