Bug 1224825 - Race condition in MessagePort::close - patch 2, r=smaug

This commit is contained in:
Andrea Marchesini 2015-11-17 23:38:13 +00:00
parent c29afb56a2
commit 5805634945
3 changed files with 14 additions and 6 deletions

View File

@ -295,7 +295,7 @@ MessagePort::MessagePort(nsPIDOMWindow* aWindow)
MessagePort::~MessagePort()
{
Close();
CloseForced();
MOZ_ASSERT(!mWorkerFeature);
}
@ -604,6 +604,13 @@ MessagePort::CloseInternal(bool aSoftly)
return;
}
// Maybe we were already closing the port but softly. In this case we call
// UpdateMustKeepAlive() to consider the empty pending message queue.
if (mState == eStateDisentangledForClose && !aSoftly) {
UpdateMustKeepAlive();
return;
}
if (mState > eStateEntangled) {
return;
}

View File

@ -276,7 +276,7 @@ MessagePortService::CloseAllDebugCheck(const nsID& aID,
#endif
void
MessagePortService::CloseAll(const nsID& aUUID)
MessagePortService::CloseAll(const nsID& aUUID, bool aForced)
{
MessagePortServiceData* data;
if (!mPorts.Get(aUUID, &data)) {
@ -299,7 +299,8 @@ MessagePortService::CloseAll(const nsID& aUUID)
// because its entangling request didn't arrive yet), we cannot close this
// channel.
MessagePortServiceData* destinationData;
if (mPorts.Get(destinationUUID, &destinationData) &&
if (!aForced &&
mPorts.Get(destinationUUID, &destinationData) &&
!destinationData->mMessages.IsEmpty() &&
destinationData->mWaitingForNewParent) {
MOZ_ASSERT(!destinationData->mNextStepCloseAll);
@ -309,7 +310,7 @@ MessagePortService::CloseAll(const nsID& aUUID)
mPorts.Remove(aUUID);
CloseAll(destinationUUID);
CloseAll(destinationUUID, aForced);
// CloseAll calls itself recursively and it can happen that it deletes
// itself. Before continuing we must check if we are still alive.
@ -410,7 +411,7 @@ MessagePortService::ForceClose(const nsID& aUUID,
return false;
}
CloseAll(aUUID);
CloseAll(aUUID, true);
return true;
}

View File

@ -46,7 +46,7 @@ public:
private:
~MessagePortService() {}
void CloseAll(const nsID& aUUID);
void CloseAll(const nsID& aUUID, bool aForced = false);
void MaybeShutdown();
class MessagePortServiceData;