Bug 1089833 - Delete reply in MessageChannel::DispatchSyncMessage and DispatchInterruptMessage if channel isn't connected. r=billm, a=lsblakk
authorAndrew McCreight <continuation@gmail.com>
Tue, 28 Oct 2014 13:53:15 -0700
changeset 225789 b978e327eccb66153bd30e72e8507c1af1c224f0
parent 225788 3919b426956c21cc5296463c32b3e4e71f8a3e39
child 225790 1fa602d38e6ecf2c77e1bcc26a5d23c001ebb281
push id7186
push userryanvm@gmail.com
push dateFri, 31 Oct 2014 01:05:56 +0000
treeherdermozilla-aurora@ee017c79f5a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, lsblakk
bugs1089833
milestone35.0a2
Bug 1089833 - Delete reply in MessageChannel::DispatchSyncMessage and DispatchInterruptMessage if channel isn't connected. r=billm, a=lsblakk
ipc/glue/MessageChannel.cpp
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -654,17 +654,17 @@ MessageChannel::OnMessageReceivedFromLin
             mWorkerLoop->PostTask(FROM_HERE, new DequeueTask(mDequeueOneTask));
         }
     }
 }
 
 bool
 MessageChannel::Send(Message* aMsg, Message* aReply)
 {
-    // See comment in DispatchUrgentMessage.
+    // See comment in DispatchSyncMessage.
     MaybeScriptBlocker scriptBlocker(this, true);
 
     // Sanity checks.
     AssertWorkerThread();
     mMonitor->AssertNotCurrentThreadOwns();
 
 #ifdef OS_WIN
     SyncStackFrame frame(this, false);
@@ -1050,17 +1050,17 @@ MessageChannel::DispatchMessage(const Me
         DispatchAsyncMessage(aMsg);
 }
 
 void
 MessageChannel::DispatchSyncMessage(const Message& aMsg)
 {
     AssertWorkerThread();
 
-    Message *reply = nullptr;
+    nsAutoPtr<Message> reply;
 
     int prio = aMsg.priority();
 
     // We don't want to run any code that might run a nested event loop here, so
     // we avoid running event handlers. Once we've sent the response to the
     // urgent message, it's okay to run event handlers again since the parent is
     // no longer blocked.
     MOZ_ASSERT_IF(prio > IPC::Message::PRIORITY_NORMAL, NS_IsMainThread());
@@ -1074,32 +1074,32 @@ MessageChannel::DispatchSyncMessage(cons
     bool dummy;
     bool& blockingVar = ShouldBlockScripts() ? gParentIsBlocked : dummy;
 
     Result rv;
     {
         AutoSetValue<bool> blocked(blockingVar, true);
         AutoSetValue<bool> sync(mDispatchingSyncMessage, true);
         AutoSetValue<int> prioSet(mDispatchingSyncMessagePriority, prio);
-        rv = mListener->OnMessageReceived(aMsg, reply);
+        rv = mListener->OnMessageReceived(aMsg, *getter_Transfers(reply));
     }
 
     if (!MaybeHandleError(rv, aMsg, "DispatchSyncMessage")) {
-        delete reply;
         reply = new Message();
         reply->set_sync();
         reply->set_priority(aMsg.priority());
         reply->set_reply();
         reply->set_reply_error();
     }
     reply->set_seqno(aMsg.seqno());
 
     MonitorAutoLock lock(*mMonitor);
-    if (ChannelConnected == mChannelState)
-        mLink->SendMessage(reply);
+    if (ChannelConnected == mChannelState) {
+        mLink->SendMessage(reply.forget());
+    }
 }
 
 void
 MessageChannel::DispatchAsyncMessage(const Message& aMsg)
 {
     AssertWorkerThread();
     MOZ_ASSERT(!aMsg.is_interrupt() && !aMsg.is_sync());
 
@@ -1164,34 +1164,34 @@ MessageChannel::DispatchInterruptMessage
         // to fix up the mRemoteStackDepthGuess here, because we're just about
         // to increment it in DispatchCall(), which will make it correct again.
     }
 
 #ifdef OS_WIN
     SyncStackFrame frame(this, true);
 #endif
 
-    Message* reply = nullptr;
+    nsAutoPtr<Message> reply;
 
     ++mRemoteStackDepthGuess;
-    Result rv = mListener->OnCallReceived(aMsg, reply);
+    Result rv = mListener->OnCallReceived(aMsg, *getter_Transfers(reply));
     --mRemoteStackDepthGuess;
 
     if (!MaybeHandleError(rv, aMsg, "DispatchInterruptMessage")) {
-        delete reply;
         reply = new Message();
         reply->set_interrupt();
         reply->set_reply();
         reply->set_reply_error();
     }
     reply->set_seqno(aMsg.seqno());
 
     MonitorAutoLock lock(*mMonitor);
-    if (ChannelConnected == mChannelState)
-        mLink->SendMessage(reply);
+    if (ChannelConnected == mChannelState) {
+        mLink->SendMessage(reply.forget());
+    }
 }
 
 void
 MessageChannel::MaybeUndeferIncall()
 {
     AssertWorkerThread();
     mMonitor->AssertCurrentThreadOwns();