Browse Source

Fix memory corruption when cleaning timer

Cheng Zhao 9 years ago
parent
commit
444f461269
2 changed files with 8 additions and 2 deletions
  1. 7 2
      atom/app/uv_task_runner.cc
  2. 1 0
      atom/app/uv_task_runner.h

+ 7 - 2
atom/app/uv_task_runner.cc

@@ -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

+ 1 - 0
atom/app/uv_task_runner.h

@@ -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_;