Bug 698075 - Use nsAutoptr<> to guarantee msg is freed; r=cjones

This commit is contained in:
Niko Matsakis 2011-11-30 13:19:49 +00:00
Родитель a6c744ffa2
Коммит b6cdc0ee29
3 изменённых файлов: 13 добавлений и 8 удалений

Просмотреть файл

@ -227,8 +227,9 @@ AsyncChannel::SynchronouslyClose()
}
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");
@ -241,15 +242,16 @@ AsyncChannel::Send(Message* msg)
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");
@ -267,7 +269,7 @@ AsyncChannel::Echo(Message* msg)
// and RPCChannel too
mIOLoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg));
NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg.forget()));
// OnEchoMessage takes ownership of |msg|
}

Просмотреть файл

@ -151,8 +151,9 @@ RPCChannel::Send(Message* msg, Message* reply)
}
bool
RPCChannel::Call(Message* msg, Message* reply)
RPCChannel::Call(Message* _msg, Message* reply)
{
nsAutoPtr<Message> msg(_msg);
AssertWorkerThread();
mMonitor.AssertNotCurrentThreadOwns();
RPC_ASSERT(!ProcessingSyncMessage(),
@ -178,7 +179,7 @@ RPCChannel::Call(Message* msg, Message* reply)
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

Просмотреть файл

@ -95,8 +95,10 @@ SyncChannel::EventOccurred()
}
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(),
@ -118,7 +120,7 @@ SyncChannel::Send(Message* msg, Message* reply)
mPendingReply = msg->type() + 1;
int32 msgSeqno = msg->seqno();
SendThroughTransport(msg);
SendThroughTransport(msg.forget());
while (1) {
bool maybeTimedOut = !SyncChannel::WaitForNotify();