|
Boost-Commit : |
From: chris_at_[hidden]
Date: 2007-11-01 18:42:27
Author: chris_kohlhoff
Date: 2007-11-01 18:42:26 EDT (Thu, 01 Nov 2007)
New Revision: 40670
URL: http://svn.boost.org/trac/boost/changeset/40670
Log:
Fix memory leak when an io_service is allowed to destruct with unfinished
async_wait operations.
Text files modified:
trunk/boost/asio/detail/timer_queue.hpp | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
Modified: trunk/boost/asio/detail/timer_queue.hpp
==============================================================================
--- trunk/boost/asio/detail/timer_queue.hpp (original)
+++ trunk/boost/asio/detail/timer_queue.hpp 2007-11-01 18:42:26 EDT (Thu, 01 Nov 2007)
@@ -163,13 +163,7 @@
// Destroy timers that are waiting to be cleaned up.
virtual void cleanup_timers()
{
- while (cleanup_timers_)
- {
- timer_base* next_timer = cleanup_timers_->next_;
- cleanup_timers_->next_ = 0;
- cleanup_timers_->destroy();
- cleanup_timers_ = next_timer;
- }
+ destroy_timer_list(cleanup_timers_);
}
// Destroy all timers.
@@ -182,11 +176,12 @@
timer_base* t = i->second;
typename hash_map<void*, timer_base*>::iterator old_i = i++;
timers_.erase(old_i);
- t->destroy();
+ destroy_timer_list(t);
}
heap_.clear();
timers_.clear();
- cleanup_timers();
+ destroy_timer_list(cancelled_timers_);
+ destroy_timer_list(cleanup_timers_);
}
private:
@@ -368,6 +363,18 @@
}
}
+ // Destroy all timers in a linked list.
+ void destroy_timer_list(timer_base*& t)
+ {
+ while (t)
+ {
+ timer_base* next = t->next_;
+ t->next_ = 0;
+ t->destroy();
+ t = next;
+ }
+ }
+
// A hash of timer token to linked lists of timers.
hash_map<void*, timer_base*> timers_;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk