]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix memory corruption when cleaning timer
authorCheng Zhao <zcbenz@gmail.com>
Wed, 21 Oct 2015 12:46:16 +0000 (20:46 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 21 Oct 2015 12:46:16 +0000 (20:46 +0800)
atom/app/uv_task_runner.cc
atom/app/uv_task_runner.h

index 23463e44e2ef1523aaf1d4179c07be9d45136dcf..f49ba259bac8eb7f23de378d9377ec560cc90178 100644 (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
index e4eac0155354333618b85ba8fabc7fb11f486090..c7302766c2d1786cc00d58c56ca529574f09ac8d 100644 (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_;