diff --git a/layout/xul/base/src/tree/src/nsTreeSelection.cpp b/layout/xul/base/src/tree/src/nsTreeSelection.cpp index d1f473ad4dc7..f0f046e497b4 100644 --- a/layout/xul/base/src/tree/src/nsTreeSelection.cpp +++ b/layout/xul/base/src/tree/src/nsTreeSelection.cpp @@ -717,7 +717,12 @@ nsTreeSelection::FireOnSelectHandler() nsCOMPtr content(do_QueryInterface(elt)); nsCOMPtr document; content->GetDocument(*getter_AddRefs(document)); - + + // we might be firing on a delay, so it's possible in rare cases that + // the document may have been destroyed by the time it fires + if (!document) + return NS_OK; + PRInt32 count = document->GetNumberOfShells(); for (PRInt32 i = 0; i < count; i++) { nsCOMPtr shell;