From 3cb9162588e956202581f8d0bc6cb8f70674e2a5 Mon Sep 17 00:00:00 2001 From: Jake Montgomery Date: Mon, 17 Nov 2014 12:01:59 -0500 Subject: [PATCH] Fixed a timer bug that could cause a timer memory leak, or incorrect behavior. Updated to v0.5.3. --- SchedulerBase.cpp | 35 +++++++++++++++++++++++++++++++++-- SchedulerBase.h | 4 ++++ configure.ac | 2 +- log.cpp | 2 +- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/SchedulerBase.cpp b/SchedulerBase.cpp index 20e5fd5..3eab298 100755 --- a/SchedulerBase.cpp +++ b/SchedulerBase.cpp @@ -82,7 +82,7 @@ class TimerImpl : public Timer else { // Remove us from active timers list. (Must remove before changing timer.) - SchedulerBase::timer_set_it found = m_activeTimers->find(this); + SchedulerBase::timer_set_it found = SchedulerBase::TimeSetFindExact(*m_activeTimers, this); if (found != m_activeTimers->end()) m_activeTimers->erase(found); @@ -226,7 +226,7 @@ class TimerImpl : public Timer if (expireChange) { - SchedulerBase::timer_set_it found = m_activeTimers->find(this); + SchedulerBase::timer_set_it found = SchedulerBase::TimeSetFindExact(*m_activeTimers, this); if (found != m_activeTimers->end()) { if (!willTimerBeSorted(found, expireTime)) @@ -679,3 +679,34 @@ bool SchedulerBase::compareTimers(const TimerImpl *lhs, const TimerImpl *rhs) // rhs. -1 if left is earlier. return (0 > timespecCompare(lhs->GetExpireTime(), rhs->GetExpireTime())); } + +/** + * Finds a TimerImpl in the timer_set. + * + * Note that timer_set::find() would return any timer that matches, which is + * defined as matching expire time. This function will **only** return an + * iterator that points to the specific TimerImpl provided. + * + * + * @param timerSet [in] - The timer set to search. + * @param target [in] - The object to search for. + * + * @return SchedulerBase::timer_set_it - An iterator to the timer, or + * timerSet.end() if no match was found. + * + */ +SchedulerBase::timer_set_it SchedulerBase::TimeSetFindExact(SchedulerBase::timer_set &timerSet, + TimerImpl *target) +{ + std::pair range; + + range = timerSet.equal_range(target); + + for (timer_set_it it = range.first; it != range.second; ++it) + { + // Compare as pointers + if (target == *it) + return it; + } + return timerSet.end(); +} diff --git a/SchedulerBase.h b/SchedulerBase.h index 2c12c80..5084ee3 100755 --- a/SchedulerBase.h +++ b/SchedulerBase.h @@ -40,6 +40,10 @@ class SchedulerBase : public Scheduler virtual Timer* MakeTimer(const char *name); virtual void FreeTimer(Timer *timer); + /** Other public functions */ + static timer_set_it TimeSetFindExact(timer_set &timerSet, TimerImpl *target); + + protected: /** * Constructor diff --git a/configure.ac b/configure.ac index d26e53a..0644a70 100755 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_PREREQ(2.61) sinclude(acx_nlnetlabs.m4) -AC_INIT(openbfdd, 0.5.2) +AC_INIT(openbfdd, 0.5.3) AM_INIT_AUTOMAKE([subdir-objects]) AC_CONFIG_SRCDIR([BeaconMain.cpp]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) diff --git a/log.cpp b/log.cpp index 9c53861..8399d01 100755 --- a/log.cpp +++ b/log.cpp @@ -31,7 +31,7 @@ LogImp::LogImp() : Logger() m_types[Log::Debug].name = "debug"; m_types[Log::Debug].logName = "debug"; m_types[Log::Debug].syslogPriority = LOG_DEBUG; - + m_types[Log::App].name = "app"; m_types[Log::App].description = "General application messages";