]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix possible crashes when quiting message loop.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 8 Jan 2014 03:55:54 +0000 (11:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 8 Jan 2014 03:55:54 +0000 (11:55 +0800)
common/node_bindings.cc
common/node_bindings.h

index 317f679599dcf3bc2cb921efc7d4c93a2153d911..5bd69a680d9a5f98f9a3b2447ecd89b62c94d8be 100644 (file)
@@ -65,7 +65,8 @@ NodeBindings::NodeBindings(bool is_browser)
     : is_browser_(is_browser),
       message_loop_(NULL),
       uv_loop_(uv_default_loop()),
-      embed_closed_(false) {
+      embed_closed_(false),
+      weak_factory_(this) {
 }
 
 NodeBindings::~NodeBindings() {
@@ -76,7 +77,6 @@ NodeBindings::~NodeBindings() {
 
   // Wait for everything to be done.
   uv_thread_join(&embed_thread_);
-  message_loop_->RunUntilIdle();
 
   // Clear uv.
   uv_sem_destroy(&embed_sem_);
@@ -209,7 +209,7 @@ void NodeBindings::UvRunOnce() {
 void NodeBindings::WakeupMainThread() {
   DCHECK(message_loop_);
   message_loop_->PostTask(FROM_HERE, base::Bind(&NodeBindings::UvRunOnce,
-                                                base::Unretained(this)));
+                                                weak_factory_.GetWeakPtr()));
 }
 
 void NodeBindings::WakeupEmbedThread() {
index 7ed22806d11513ef4d29b91f9893add3cd2dd5c2..f777c220afc1f31069c2dd96ca27ac662961ec9e 100644 (file)
@@ -6,6 +6,7 @@
 #define ATOM_COMMON_NODE_BINDINGS_H_
 
 #include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
 #include "v8/include/v8.h"
 #include "vendor/node/deps/uv/include/uv.h"
 
@@ -83,6 +84,8 @@ class NodeBindings {
   // Semaphore to wait for main loop in the embed thread.
   uv_sem_t embed_sem_;
 
+  base::WeakPtrFactory<NodeBindings> weak_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(NodeBindings);
 };