Bug 1105468 - In SendResponse, send an invalid FD to the child if we failed to open the file. r=bent
authorAndrew McCreight <continuation@gmail.com>
Fri, 09 Jan 2015 13:10:14 -0800
changeset 236098 2dc60df56da1e3de58531b3abc418acb470ce3a4
parent 236097 7b8870e4821e481fcc58447f8b9e4c2421c6b5cd
child 236099 cc46a830c58daee491985d863741eee781221904
push id384
push usermartin.thomson@gmail.com
push dateFri, 09 Jan 2015 21:26:39 +0000
reviewersbent
bugs1105468
milestone37.0a1
Bug 1105468 - In SendResponse, send an invalid FD to the child if we failed to open the file. r=bent
dom/ipc/TabParent.cpp
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -137,31 +137,37 @@ private:
         return NS_OK;
     }
 
     void SendResponse()
     {
         MOZ_ASSERT(NS_IsMainThread());
         MOZ_ASSERT(mTabParent);
         MOZ_ASSERT(mEventTarget);
-        MOZ_ASSERT(mFD);
 
         nsRefPtr<TabParent> tabParent;
         mTabParent.swap(tabParent);
 
         using mozilla::ipc::FileDescriptor;
 
-        FileDescriptor::PlatformHandleType handle =
-            FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFD));
+        FileDescriptor fd;
+        if (mFD) {
+            FileDescriptor::PlatformHandleType handle =
+                FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFD));
+            fd = FileDescriptor(handle);
+        }
 
         // Our TabParent may have been destroyed already.  If so, don't send any
         // fds over, just go back to the IO thread and close them.
         if (!tabParent->IsDestroyed()) {
-          mozilla::unused << tabParent->SendCacheFileDescriptor(mPath,
-                                                                FileDescriptor(handle));
+            mozilla::unused << tabParent->SendCacheFileDescriptor(mPath, fd);
+        }
+
+        if (!mFD) {
+            return;
         }
 
         nsCOMPtr<nsIEventTarget> eventTarget;
         mEventTarget.swap(eventTarget);
 
         if (NS_FAILED(eventTarget->Dispatch(this, NS_DISPATCH_NORMAL))) {
             NS_WARNING("Failed to dispatch to stream transport service!");