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 225882 926c3f3f1f3a
parent 225881 72bdce765298
child 225883 e35984b580fb
push id4055
push userryanvm@gmail.com
push date2014-10-31 01:17 +0000
treeherdermozilla-beta@12a8a2d96453 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, lsblakk
bugs1089833
milestone34.0
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
@@ -601,17 +601,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);
 
     // Sanity checks.
     AssertWorkerThread();
     mMonitor->AssertNotCurrentThreadOwns();
 
 #ifdef OS_WIN
     SyncStackFrame frame(this, false);
@@ -1115,34 +1115,34 @@ MessageChannel::DispatchMessage(const Me
         DispatchAsyncMessage(aMsg);
 }
 
 void
 MessageChannel::DispatchSyncMessage(const Message& aMsg)
 {
     AssertWorkerThread();
 
-    Message *reply = nullptr;
+    nsAutoPtr<Message> reply;
 
     mDispatchingSyncMessage = true;
-    Result rv = mListener->OnMessageReceived(aMsg, reply);
+    Result rv = mListener->OnMessageReceived(aMsg, *getter_Transfers(reply));
     mDispatchingSyncMessage = false;
 
     if (!MaybeHandleError(rv, aMsg, "DispatchSyncMessage")) {
-        delete reply;
         reply = new Message();
         reply->set_sync();
         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::DispatchUrgentMessage(const Message& aMsg)
 {
     AssertWorkerThread();
     MOZ_ASSERT(aMsg.is_urgent());
 
@@ -1287,34 +1287,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();