ipcRenderer: fix crash with multiple listeners to sync message
authordeepak1556 <hop2deep@gmail.com>
Thu, 5 May 2016 21:22:59 +0000 (02:52 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Thu, 5 May 2016 21:22:59 +0000 (02:52 +0530)
atom/browser/api/event.cc
spec/api-ipc-spec.js

index f456cf2..2554e4a 100644 (file)
@@ -45,7 +45,10 @@ bool Event::SendReply(const base::string16& json) {
     return false;
 
   AtomViewHostMsg_Message_Sync::WriteReplyParams(message_, json);
-  return sender_->Send(message_);
+  bool success = sender_->Send(message_);
+  message_ = NULL;
+  sender_ = NULL;
+  return success;
 }
 
 // static
index c986892..d865be9 100644 (file)
@@ -200,6 +200,21 @@ describe('ipc module', function () {
       })
       w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
     })
+
+    it('does not crash when reply is sent by multiple listeners', function (done) {
+      var w = new BrowserWindow({
+        show: false
+      })
+      ipcMain.on('send-sync-message', function (event) {
+        event.returnValue = null
+      })
+      ipcMain.on('send-sync-message', function (event) {
+        event.returnValue = null
+        w.destroy()
+        done()
+      })
+      w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
+    })
   })
 
   describe('remote listeners', function () {