Bug 884334 - Make sure WidgetShutdownObserver doesn't attempt to use the widget pointer after it has been destroyed. r=roc

This commit is contained in:
Matt Woodrow 2013-06-19 14:21:01 +12:00
parent 9e8bcc1d69
commit f84e41801b
2 changed files with 7 additions and 2 deletions

View File

@ -130,7 +130,8 @@ WidgetShutdownObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0 &&
mWidget) {
mWidget->Shutdown();
nsContentUtils::UnregisterShutdownObserver(this);
}
@ -195,6 +196,11 @@ nsBaseWidget::~nsBaseWidget()
}
if (mShutdownObserver) {
// If the shutdown observer is currently processing observers,
// then UnregisterShutdownObserver won't stop our Observer
// function from being called. Make sure we don't try
// to reference the dead widget.
mShutdownObserver->mWidget = nullptr;
nsContentUtils::UnregisterShutdownObserver(mShutdownObserver);
}

View File

@ -51,7 +51,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
private:
nsBaseWidget *mWidget;
};