Fix memory corruption when cleaning timer

This commit is contained in:
Cheng Zhao 2015-10-21 20:46:16 +08:00
parent 2d410ede48
commit 444f461269
2 changed files with 8 additions and 2 deletions

View file

@ -48,8 +48,13 @@ void UvTaskRunner::OnTimeout(uv_timer_t* timer) {
self->tasks_[timer].Run();
self->tasks_.erase(timer);
uv_unref(reinterpret_cast<uv_handle_t*>(timer));
delete timer;
uv_timer_stop(timer);
uv_close(reinterpret_cast<uv_handle_t*>(timer), UvTaskRunner::OnClose);
}
// static
void UvTaskRunner::OnClose(uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
}
} // namespace atom

View file

@ -31,6 +31,7 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
private:
static void OnTimeout(uv_timer_t* timer);
static void OnClose(uv_handle_t* handle);
uv_loop_t* loop_;