Bug 1054819 - Ensure that the dictionary is released on the main thread. r=ehsan

CLOSED TREE
This commit is contained in:
Michal Novotny 2014-08-20 04:28:00 -04:00
parent 9dd31134f4
commit 37a95fbda8

View File

@ -18,6 +18,7 @@
#include "nsUnicharInputStream.h"
#include "nsIRunnable.h"
#include "nsThreadUtils.h"
#include "nsProxyRelease.h"
#define MOZ_PERSONAL_DICT_NAME "persdict.dat"
@ -54,11 +55,18 @@ public:
NS_IMETHOD Run()
{
if (!NS_IsMainThread()) {
mDict->SyncLoad();
mDict->SyncLoad();
// Release refptr on the mainthread
NS_DispatchToMainThread(this);
// Release the dictionary on the main thread
mozPersonalDictionary *dict;
mDict.forget(&dict);
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
if (mainThread) {
NS_ProxyRelease(mainThread, static_cast<mozIPersonalDictionary *>(dict));
} else {
// It's better to leak the dictionary than to release it on a wrong thread
NS_WARNING("Cannot get main thread, leaking mozPersonalDictionary.");
}
return NS_OK;