Bug 1048011: fix a race condition that leaks PProcLoaderParent. r=khuey

--HG--
extra : rebase_source : 18146b718be5d884915216ec453a153e30923f6c
This commit is contained in:
Cervantes Yu 2014-08-11 15:50:20 +08:00
parent 8e25274ce6
commit d306472784

View File

@ -117,29 +117,35 @@ static const int kBeginReserveFileDescriptor = STDERR_FILENO + 1;
class ProcLoaderParent : public PProcLoaderParent
{
private:
nsAutoPtr<FileDescriptor> mChannelFd; // To keep a reference.
public:
ProcLoaderParent(FileDescriptor *aFd) : mChannelFd(aFd) {}
ProcLoaderParent() {}
virtual ~ProcLoaderParent() {}
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
virtual bool RecvLoadComplete(const int32_t &aPid,
const int32_t &aCookie) MOZ_OVERRIDE;
virtual void OnChannelError() MOZ_OVERRIDE;
};
void
ProcLoaderParent::ActorDestroy(ActorDestroyReason aWhy)
{
if (aWhy == AbnormalShutdown) {
NS_WARNING("ProcLoaderParent is destroyed abnormally.");
}
if (sProcLoaderClientOnDeinit) {
// Get error for closing while the channel is already error.
return;
}
// Destroy self asynchronously.
ProcLoaderClientDeinit();
}
static void
_ProcLoaderParentDestroy(PProcLoaderParent *aLoader)
{
aLoader->Close();
delete aLoader;
sProcLoaderClientOnDeinit = false;
}
@ -148,7 +154,6 @@ bool
ProcLoaderParent::RecvLoadComplete(const int32_t &aPid,
const int32_t &aCookie)
{
ProcLoaderClientDeinit();
return true;
}
@ -160,17 +165,6 @@ CloseFileDescriptors(FdArray& aFds)
}
}
void
ProcLoaderParent::OnChannelError()
{
if (sProcLoaderClientOnDeinit) {
// Get error for closing while the channel is already error.
return;
}
NS_WARNING("ProcLoaderParent is in channel error");
ProcLoaderClientDeinit();
}
/**
* Initialize the client of B2G loader for loader itself.
*
@ -204,11 +198,11 @@ ProcLoaderClientGeckoInit()
sProcLoaderClientGeckoInitialized = true;
FileDescriptor *fd = new FileDescriptor(sProcLoaderChannelFd);
close(sProcLoaderChannelFd);
TransportDescriptor fd;
fd.mFd = base::FileDescriptor(sProcLoaderChannelFd, /*auto_close=*/ false);
sProcLoaderChannelFd = -1;
Transport *transport = OpenDescriptor(*fd, Transport::MODE_CLIENT);
sProcLoaderParent = new ProcLoaderParent(fd);
Transport *transport = OpenDescriptor(fd, Transport::MODE_CLIENT);
sProcLoaderParent = new ProcLoaderParent();
sProcLoaderParent->Open(transport,
sProcLoaderPid,
XRE_GetIOMessageLoop(),
@ -548,8 +542,8 @@ ProcLoaderServiceRun(pid_t aPeerPid, int aFd,
MOZ_CRASH();
}
FileDescriptor fd(aFd);
close(aFd);
TransportDescriptor fd;
fd.mFd = base::FileDescriptor(aFd, /*auto_close =*/false);
MOZ_ASSERT(!sProcLoaderServing);
MessageLoop loop;