diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index b7d15ed2a68a..01864a30745e 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -121,6 +121,7 @@ protected: nsICmdLineService* mCmdLineService; nsIWindowMediator* mWindowMediator; nsCOMPtr mHiddenWindow; + PRBool mDeleteCalled; }; nsAppShellService::nsAppShellService() : mWindowMediator( NULL ) @@ -130,10 +131,12 @@ nsAppShellService::nsAppShellService() : mWindowMediator( NULL ) mAppShell = nsnull; mWindowList = nsnull; mCmdLineService = nsnull; + mDeleteCalled = PR_FALSE; } nsAppShellService::~nsAppShellService() { + mDeleteCalled = PR_TRUE; NS_IF_RELEASE(mAppShell); NS_IF_RELEASE(mWindowList); NS_IF_RELEASE(mCmdLineService); @@ -721,6 +724,14 @@ nsAppShellService::UnregisterTopLevelWindow(nsIWebShellWindow* aWindow) service->UnregisterWindow( aWindow ); nsServiceManager::ReleaseService(kWindowMediatorCID, service); } + + if (mDeleteCalled) { + // return an error code in order to: + // - avoid doing anything with other member variables while we are in the destructor + // - notify the caller not to release the AppShellService after unregistering the window + // (we don't want to be deleted twice consecutively to mHiddenWindow->Close() in our destructor) + return NS_ERROR_FAILURE; + } nsresult rv; diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index da03c6954398..c8f715e91a09 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -465,7 +465,8 @@ nsWebShellWindow::Close() return rv; rv = appShell->UnregisterTopLevelWindow(this); - nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + if (NS_SUCCEEDED(rv)) + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); return rv; }