From: Gunnar Beutner Date: Sun, 20 Apr 2014 05:21:38 +0000 (+0200) Subject: Fix crash in Timer::AdjustTimers. X-Git-Tag: v0.0.10~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9905a4e09b876d7432b6036939c9e57b6752ca91;p=icinga2 Fix crash in Timer::AdjustTimers. Refs #4865 --- diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 8ec29f4b2..f39ce3b55 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -23,6 +23,7 @@ #include "base/utility.h" #include "base/logger_fwd.h" #include +#include #include #include #include @@ -240,9 +241,10 @@ void Timer::AdjustTimers(double adjustment) typedef boost::multi_index::nth_index::type TimerView; TimerView& idx = boost::get<1>(l_Timers); - TimerView::iterator it; - for (it = idx.begin(); it != idx.end(); it++) { - Timer::Ptr timer = it->lock(); + std::vector timers; + + BOOST_FOREACH(const Timer::WeakPtr& wtimer, idx) { + Timer::Ptr timer = wtimer.lock(); if (!timer) continue; @@ -250,11 +252,14 @@ void Timer::AdjustTimers(double adjustment) if (abs(now - (timer->m_Next + adjustment)) < abs(now - timer->m_Next)) { timer->m_Next += adjustment; - l_Timers.erase(timer); - l_Timers.insert(timer); + timers.push_back(timer); } } + BOOST_FOREACH(const Timer::Ptr& timer, timers) { + l_Timers.erase(timer); + l_Timers.insert(timer); + } /* Notify the worker that we've rescheduled some timers. */ l_CV.notify_all(); }