Bug 887889 - Fix leak in RemoteSpellCheckingEngineChild r=Ehsan

The work to migrate to Sqlite.jsm seems to have caused a timing problem
in our tests where shutdown the content process while this IPC message
is still unresolved. This causes us to destroy RemoteSpellCheckingEngineChild
without it having processed its RecvNotiy..., leading to the promise being
leaked. As far as I can tell this resolves all of our leak issues on try.

MozReview-Commit-ID: GdwVIp5dj1m

--HG--
extra : rebase_source : b7bf5838c53e40b49bea17df123028a2dbd26e5e
This commit is contained in:
Doug Thayer 2018-04-19 14:33:18 -07:00
parent 957135b686
commit ce5461c0d3
3 changed files with 23 additions and 7 deletions

View File

@ -896,7 +896,10 @@ EditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
fetcher->mCallback->EditorSpellCheckDone();
}
},
[self, fetcher]() {
[self, fetcher](nsresult aError) {
if (aError == NS_ERROR_ABORT) {
return;
}
// May be dictionary was uninstalled ?
// Clear the content preference and continue.
ClearCurrentDictionary(self->mEditor);

View File

@ -17,22 +17,29 @@ RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild()
// null out the owner's SpellcheckEngineChild to prevent state corruption
// during shutdown
mOwner->DeleteRemoteEngine();
// ensure we don't leak any promise holders for which we haven't yet
// received responses
for (UniquePtr<MozPromiseHolder<GenericPromise>>& promiseHolder : mResponsePromises) {
promiseHolder->RejectIfExists(NS_ERROR_ABORT, __func__);
}
}
RefPtr<GenericPromise>
RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
const nsTArray<nsString>& aList)
{
MozPromiseHolder<GenericPromise>* promiseHolder =
new MozPromiseHolder<GenericPromise>();
UniquePtr<MozPromiseHolder<GenericPromise>> promiseHolder =
MakeUnique<MozPromiseHolder<GenericPromise>>();
if (!SendSetDictionaryFromList(
aList,
reinterpret_cast<intptr_t>(promiseHolder))) {
delete promiseHolder;
reinterpret_cast<intptr_t>(promiseHolder.get()))) {
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
}
RefPtr<GenericPromise> result = promiseHolder->Ensure(__func__);
// promiseHolder will removed by receive message
return promiseHolder->Ensure(__func__);
mResponsePromises.AppendElement(Move(promiseHolder));
return Move(result);
}
mozilla::ipc::IPCResult
@ -48,7 +55,12 @@ RemoteSpellcheckEngineChild::RecvNotifyOfCurrentDictionary(
} else {
promiseHolder->ResolveIfExists(true, __func__);
}
delete promiseHolder;
for (uint32_t i = 0; i < mResponsePromises.Length(); ++i) {
if (mResponsePromises[i].get() == promiseHolder) {
mResponsePromises.RemoveElementAt(i);
break;
}
}
return IPC_OK();
}

View File

@ -28,6 +28,7 @@ public:
private:
mozSpellChecker *mOwner;
nsTArray<UniquePtr<MozPromiseHolder<GenericPromise>>> mResponsePromises;
};
} //namespace mozilla