Bug 1081992 Needs null check at notifying TextComposition of composition event being discarded r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 15 Oct 2014 00:40:06 +0900
changeset 210360 a19c2e8143cb4099f594fcc77418f0fc69914cbc
parent 210359 a14b8bf72b1655f2dd70d1a7bc022abb6f9bf96d
child 210361 64aa0ab1f87b4823e32ccc5c81007868dc1ddfd4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1081992
milestone36.0a1
Bug 1081992 Needs null check at notifying TextComposition of composition event being discarded r=smaug
dom/events/IMEStateManager.cpp
--- a/dom/events/IMEStateManager.cpp
+++ b/dom/events/IMEStateManager.cpp
@@ -974,16 +974,26 @@ IMEStateManager::OnCompositionEventDisca
   // Ignore compositionstart for now because sTextCompositions may not have
   // been created yet.
   if (aCompositionEvent->message == NS_COMPOSITION_START) {
     return;
   }
 
   nsRefPtr<TextComposition> composition =
     sTextCompositions->GetCompositionFor(aCompositionEvent->widget);
+  if (!composition) {
+    // If the PresShell has been being destroyed during composition,
+    // a TextComposition instance for the composition was already removed from
+    // the array and destroyed in OnDestroyPresContext().  Therefore, we may
+    // fail to retrieve a TextComposition instance here.
+    PR_LOG(sISMLog, PR_LOG_ALWAYS,
+      ("ISM:   IMEStateManager::OnCompositionEventDiscarded(), "
+       "TextComposition instance for the widget has already gone"));
+    return;
+  }
   composition->OnCompositionEventDiscarded(aCompositionEvent);
 }
 
 // static
 nsresult
 IMEStateManager::NotifyIME(IMEMessage aMessage,
                            nsIWidget* aWidget)
 {