Bug 1761085 - Check for existence of mEngine in mozSpellChecker; r=smaug

With the changes to EditorSpellCheck::SetFallbackDictionary to use a
promise chain to support calling either SetCurrentDictionaryFromList or
SetCurrentDictionaries as required, it is now possible that
RemoteSpellCheckEngineChild is destroyed by the time the second promise
runs. During destruction, RemoteSpellCheckEngineChild calls
mozSpellChecker::DeleteRemoteEngine, which sets mEngine to nullptr.
This patch adds a nullptr check for mEngine in both
SetCurrentDictionaryFromList and SetCurrentDictionaries.

Differential Revision: https://phabricator.services.mozilla.com/D141983
This commit is contained in:
Dan Minor 2022-03-24 19:23:56 +00:00
parent 7251e4d3f9
commit 37130e3638

View File

@ -466,6 +466,11 @@ nsresult mozSpellChecker::SetCurrentDictionary(const nsCString& aDictionary) {
RefPtr<GenericPromise> mozSpellChecker::SetCurrentDictionaries(
const nsTArray<nsCString>& aDictionaries) {
if (XRE_IsContentProcess()) {
if (!mEngine) {
mCurrentDictionaries.Clear();
return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
}
// mCurrentDictionaries will be set by RemoteSpellCheckEngineChild
return mEngine->SetCurrentDictionaries(aDictionaries);
}
@ -518,6 +523,11 @@ RefPtr<GenericPromise> mozSpellChecker::SetCurrentDictionaryFromList(
}
if (XRE_IsContentProcess()) {
if (!mEngine) {
mCurrentDictionaries.Clear();
return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
}
// mCurrentDictionaries will be set by RemoteSpellCheckEngineChild
return mEngine->SetCurrentDictionaryFromList(aList);
}