Skip to content

Commit

Permalink
Merge pull request #11 from JakeMont/timer-bug-fix
Browse files Browse the repository at this point in the history
Fixed a timer bug that could cause a timer memory leak, or incorrect behavior. Updated to v0.5.3.
  • Loading branch information
JakeMont committed Nov 17, 2014
2 parents 1c099fc + 3cb9162 commit 895cfb5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
35 changes: 33 additions & 2 deletions SchedulerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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<timer_set_it, timer_set_it> 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();
}
4 changes: 4 additions & 0 deletions SchedulerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])])
Expand Down
2 changes: 1 addition & 1 deletion log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 895cfb5

Please sign in to comment.