diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 28a686713262..60db3e6cb982 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -575,6 +575,11 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) nsCOMPtr focusedWindow; focusController->GetFocusedWindow(getter_AddRefs(focusedWindow)); if (focusedWindow) { + // It's possible for focusing the window to cause it to close. + // To avoid holding a pointer to deleted memory, keep a reference + // on eventWindow. -bryner + nsCOMPtr kungFuDeathGrip(eventWindow); + focusController->SetSuppressFocus(PR_TRUE, "Activation Suppression"); domWindow->Focus(); // This sets focus, but we'll ignore it. // A subsequent activate will cause us to stop suppressing.