Bug 1359106 - Make sure AltDataOutputStreamParent::SendError is not called after ActorDestroy r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 30 Apr 2017 18:08:25 +0200
changeset 356012 54f47d1997e951aa70ac5d81a905b9dc730c4566
parent 356011 545f5678ceaf25aa1d6be4dcb364453ec4e042ff
child 356013 9530e0ce7d55f0b22a7cd10aa332dbc8a2fc4b49
push id31754
push userkwierso@gmail.com
push dateWed, 03 May 2017 00:28:51 +0000
treeherdermozilla-central@5eaf2d70eded [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1359106
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359106 - Make sure AltDataOutputStreamParent::SendError is not called after ActorDestroy r=bagder MozReview-Commit-ID: I2m4K7MhQoA
netwerk/protocol/http/AltDataOutputStreamParent.cpp
netwerk/protocol/http/AltDataOutputStreamParent.h
--- a/netwerk/protocol/http/AltDataOutputStreamParent.cpp
+++ b/netwerk/protocol/http/AltDataOutputStreamParent.cpp
@@ -11,61 +11,67 @@
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ISUPPORTS0(AltDataOutputStreamParent)
 
 AltDataOutputStreamParent::AltDataOutputStreamParent(nsIOutputStream* aStream)
   : mOutputStream(aStream)
   , mStatus(NS_OK)
+  , mIPCOpen(true)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
 }
 
 AltDataOutputStreamParent::~AltDataOutputStreamParent()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
 }
 
 mozilla::ipc::IPCResult
 AltDataOutputStreamParent::RecvWriteData(const nsCString& data)
 {
   if (NS_FAILED(mStatus)) {
-    Unused << SendError(mStatus);
+    if (mIPCOpen) {
+      Unused << SendError(mStatus);
+    }
     return IPC_OK();
   }
   nsresult rv;
   uint32_t n;
   if (mOutputStream) {
     rv = mOutputStream->Write(data.BeginReading(), data.Length(), &n);
     MOZ_ASSERT(n == data.Length());
-    if (NS_FAILED(rv)) {
+    if (NS_FAILED(rv) && mIPCOpen) {
       Unused << SendError(rv);
     }
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 AltDataOutputStreamParent::RecvClose()
 {
   if (NS_FAILED(mStatus)) {
-    Unused << SendError(mStatus);
+    if (mIPCOpen) {
+      Unused << SendError(mStatus);
+    }
     return IPC_OK();
   }
   nsresult rv;
   if (mOutputStream) {
     rv = mOutputStream->Close();
-    if (NS_FAILED(rv)) {
+    if (NS_FAILED(rv) && mIPCOpen) {
       Unused << SendError(rv);
     }
     mOutputStream = nullptr;
   }
   return IPC_OK();
 }
 
 void
 AltDataOutputStreamParent::ActorDestroy(ActorDestroyReason aWhy)
 {
+  mIPCOpen = false;
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/http/AltDataOutputStreamParent.h
+++ b/netwerk/protocol/http/AltDataOutputStreamParent.h
@@ -39,14 +39,15 @@ public:
   void SetError(nsresult status) { mStatus = status; }
 
 private:
   virtual ~AltDataOutputStreamParent();
   nsCOMPtr<nsIOutputStream> mOutputStream;
   // In case any error occurs mStatus will be != NS_OK, and this status code will
   // be sent to the content process asynchronously.
   nsresult mStatus;
+  bool     mIPCOpen;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_AltDataOutputStreamParent_h