diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index f876ec222093..0dba77992d74 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -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(); } }