Bug 1105468 - OpenFileAndSendFDRunnable::OpenFile needs to ensure we don't release off main thread. r=khuey

If any of the file operations fail, we need to ensure we still dispatch to the main thread.

If the dispatch fails, leak the runnable (and the things it owns) rather than crash when we try to release them off main thread.
This commit is contained in:
Andrew McCreight 2014-11-26 13:05:00 +01:00
parent 59e59866db
commit 8d88c3a6f8

View File

@ -118,6 +118,7 @@ public:
private:
~OpenFileAndSendFDRunnable()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mFD);
}
@ -170,7 +171,8 @@ private:
}
}
void OpenFile()
// Helper method to avoid gnarly control flow for failures.
void OpenFileImpl()
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(!mFD);
@ -184,10 +186,21 @@ private:
NS_ENSURE_SUCCESS_VOID(rv);
mFD = fd;
}
void OpenFile()
{
MOZ_ASSERT(!NS_IsMainThread());
OpenFileImpl();
if (NS_FAILED(NS_DispatchToMainThread(this))) {
NS_WARNING("Failed to dispatch to main thread!");
// Intentionally leak the runnable (but not the fd) rather
// than crash when trying to release a main thread object
// off the main thread.
NS_ADDREF(this);
CloseFile();
}
}