Bug 698075 - Use nsAutoptr<> to guarantee msg is freed; r=cjones
authorNiko Matsakis <nmatsakis@mozilla.com>
Wed, 30 Nov 2011 13:19:49 +0000
changeset 81005 1a01206eba24dbecffcc29cc1631e359bf90ddca
parent 81004 f212a34be46578bf4aab089b8c1c3cb0701b2a4d
child 81006 26bac72ef06019b81f135ace6b1283e7c01f60f5
push id3682
push userbmo@edmorley.co.uk
push dateWed, 30 Nov 2011 13:24:37 +0000
treeherdermozilla-inbound@26bac72ef060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs698075
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 698075 - Use nsAutoptr<> to guarantee msg is freed; r=cjones
ipc/glue/AsyncChannel.cpp
ipc/glue/RPCChannel.cpp
ipc/glue/SyncChannel.cpp
--- a/ipc/glue/AsyncChannel.cpp
+++ b/ipc/glue/AsyncChannel.cpp
@@ -222,39 +222,41 @@ AsyncChannel::SynchronouslyClose()
     mIOLoop->PostTask(
         FROM_HERE, NewRunnableMethod(this, &AsyncChannel::OnCloseChannel));
 
     while (ChannelClosed != mChannelState)
         mMonitor.Wait();
 }
 
 bool
-AsyncChannel::Send(Message* msg)
+AsyncChannel::Send(Message* _msg)
 {
+    nsAutoPtr<Message> msg(_msg);
     AssertWorkerThread();
     mMonitor.AssertNotCurrentThreadOwns();
     NS_ABORT_IF_FALSE(MSG_ROUTING_NONE != msg->routing_id(), "need a route");
 
     {
         MonitorAutoLock lock(mMonitor);
 
         if (!Connected()) {
             ReportConnectionError("AsyncChannel");
             return false;
         }
 
-        SendThroughTransport(msg);
+        SendThroughTransport(msg.forget());
     }
 
     return true;
 }
 
 bool
-AsyncChannel::Echo(Message* msg)
+AsyncChannel::Echo(Message* _msg)
 {
+    nsAutoPtr<Message> msg(_msg);
     AssertWorkerThread();
     mMonitor.AssertNotCurrentThreadOwns();
     NS_ABORT_IF_FALSE(MSG_ROUTING_NONE != msg->routing_id(), "need a route");
 
     {
         MonitorAutoLock lock(mMonitor);
 
         if (!Connected()) {
@@ -262,17 +264,17 @@ AsyncChannel::Echo(Message* msg)
             return false;
         }
 
         // NB: Go through this OnMessageReceived indirection so that
         // echoing this message does the right thing for SyncChannel
         // and RPCChannel too
         mIOLoop->PostTask(
             FROM_HERE,
-            NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg));
+            NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg.forget()));
         // OnEchoMessage takes ownership of |msg|
     }
 
     return true;
 }
 
 void
 AsyncChannel::OnDispatchMessage(const Message& msg)
--- a/ipc/glue/RPCChannel.cpp
+++ b/ipc/glue/RPCChannel.cpp
@@ -146,18 +146,19 @@ bool
 RPCChannel::Send(Message* msg, Message* reply)
 {
     Message copy = *msg;
     CxxStackFrame f(*this, OUT_MESSAGE, &copy);
     return SyncChannel::Send(msg, reply);
 }
 
 bool
-RPCChannel::Call(Message* msg, Message* reply)
+RPCChannel::Call(Message* _msg, Message* reply)
 {
+    nsAutoPtr<Message> msg(_msg);
     AssertWorkerThread();
     mMonitor.AssertNotCurrentThreadOwns();
     RPC_ASSERT(!ProcessingSyncMessage(),
                "violation of sync handler invariant");
     RPC_ASSERT(msg->is_rpc(), "can only Call() RPC messages here");
 
 #ifdef OS_WIN
     SyncStackFrame frame(this, true);
@@ -173,17 +174,17 @@ RPCChannel::Call(Message* msg, Message* 
         return false;
     }
 
     msg->set_seqno(NextSeqno());
     msg->set_rpc_remote_stack_depth_guess(mRemoteStackDepthGuess);
     msg->set_rpc_local_stack_depth(1 + StackDepth());
     mStack.push(*msg);
 
-    SendThroughTransport(msg);
+    SendThroughTransport(msg.forget());
 
     while (1) {
         // if a handler invoked by *Dispatch*() spun a nested event
         // loop, and the connection was broken during that loop, we
         // might have already processed the OnError event. if so,
         // trying another loop iteration will be futile because
         // channel state will have been cleared
         if (!Connected()) {
--- a/ipc/glue/SyncChannel.cpp
+++ b/ipc/glue/SyncChannel.cpp
@@ -90,18 +90,20 @@ SyncChannel::EventOccurred()
     AssertWorkerThread();
     mMonitor.AssertCurrentThreadOwns();
     NS_ABORT_IF_FALSE(AwaitingSyncReply(), "not in wait loop");
 
     return (!Connected() || 0 != mRecvd.type() || mRecvd.is_reply_error());
 }
 
 bool
-SyncChannel::Send(Message* msg, Message* reply)
+SyncChannel::Send(Message* _msg, Message* reply)
 {
+    nsAutoPtr<Message> msg(_msg);
+
     AssertWorkerThread();
     mMonitor.AssertNotCurrentThreadOwns();
     NS_ABORT_IF_FALSE(!ProcessingSyncMessage(),
                       "violation of sync handler invariant");
     NS_ABORT_IF_FALSE(msg->is_sync(), "can only Send() sync messages here");
 
 #ifdef OS_WIN
     SyncStackFrame frame(this, false);
@@ -113,17 +115,17 @@ SyncChannel::Send(Message* msg, Message*
 
     if (!Connected()) {
         ReportConnectionError("SyncChannel");
         return false;
     }
 
     mPendingReply = msg->type() + 1;
     int32 msgSeqno = msg->seqno();
-    SendThroughTransport(msg);
+    SendThroughTransport(msg.forget());
 
     while (1) {
         bool maybeTimedOut = !SyncChannel::WaitForNotify();
 
         if (EventOccurred())
             break;
 
         if (maybeTimedOut && !ShouldContinueFromTimeout())