Bug 1105468 - OpenFileAndSendFDRunnable::OpenFile needs to ensure we don't release off main thread. r=bent
authorAndrew McCreight <continuation@gmail.com>
Fri, 09 Jan 2015 13:10:14 -0800
changeset 223124 7b8870e4821e481fcc58447f8b9e4c2421c6b5cd
parent 223123 f0cd9e9e87aa30a6c7f0d53c45a0417a6b4f281a
child 223125 2dc60df56da1e3de58531b3abc418acb470ce3a4
push id10769
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 14:15:52 +0000
treeherderfx-team@0e9765732906 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1105468
milestone37.0a1
Bug 1105468 - OpenFileAndSendFDRunnable::OpenFile needs to ensure we don't release off main thread. r=bent
dom/ipc/TabParent.cpp
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -166,34 +166,46 @@ private:
             NS_WARNING("Failed to dispatch to stream transport service!");
 
             // It's probably safer to take the main thread IO hit here rather
             // than leak a file descriptor.
             CloseFile();
         }
     }
 
-    void OpenFile()
+    // Helper method to avoid gnarly control flow for failures.
+    void OpenFileImpl()
     {
         MOZ_ASSERT(!NS_IsMainThread());
         MOZ_ASSERT(!mFD);
 
         nsCOMPtr<nsIFile> file;
         nsresult rv = NS_NewLocalFile(mPath, false, getter_AddRefs(file));
         NS_ENSURE_SUCCESS_VOID(rv);
 
         PRFileDesc* fd;
         rv = file->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
         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.
+            mTabParent.forget();
             CloseFile();
         }
     }
 
     void CloseFile()
     {
         // It's possible for this to happen on the main thread if the dispatch
         // to the stream service fails after we've already opened the file so