Bug 778355 - Don't clear mWindow in nsWebShellWindow's destructor; nsXULWindow will clear it when it's destroyed. r=roc

Also, in nsWindowMediator's shutdown observer, release all of our nsXULWindow references after we release mListLock.  Without this, nsXULWindow's destructor can call back into nsWindowMediator, try to acquire mListLock, and deadlock.
This commit is contained in:
Justin Lebar 2012-08-02 10:38:43 -04:00
parent d390f58ab6
commit 83da4d548c
2 changed files with 13 additions and 9 deletions

View File

@ -92,12 +92,6 @@ nsWebShellWindow::nsWebShellWindow(PRUint32 aChromeFlags)
nsWebShellWindow::~nsWebShellWindow()
{
if (mWindow) {
mWindow->SetClientData(0);
mWindow->Destroy();
mWindow = nullptr; // Force release here.
}
MutexAutoLock lock(mSPTimerLock);
if (mSPTimer)
mSPTimer->Cancel();

View File

@ -757,9 +757,19 @@ nsWindowMediator::Observe(nsISupports* aSubject,
const PRUnichar* aData)
{
if (!strcmp(aTopic, "xpcom-shutdown") && mReady) {
MutexAutoLock lock(mListLock);
while (mOldestWindow)
UnregisterWindow(mOldestWindow);
// Unregistering a window may cause its destructor to run, causing it to
// call into the window mediator, try to acquire mListLock, and deadlock.
// Our solution is to hold strong refs to all windows until we release
// mListLock.
nsTArray<nsCOMPtr<nsIXULWindow> > windows;
{
MutexAutoLock lock(mListLock);
while (mOldestWindow) {
windows.AppendElement(mOldestWindow->mWindow);
UnregisterWindow(mOldestWindow);
}
}
mReady = false;
}
return NS_OK;