Bug 1571283 - Add null check for mObserver r=baku a=RyanVM
authorKershaw Chang <kershaw@mozilla.com>
Thu, 15 Aug 2019 12:52:54 +0000
changeset 545218 a7d9c83b8ab0622bfbb8ff61c95130b9952855f8
parent 545217 ff98f2d770a23556ef02667a69414a85b0915a62
child 545219 a533d91e3e8dd98a4638a1158485daf9ac758089
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, RyanVM
bugs1571283
milestone69.0
Bug 1571283 - Add null check for mObserver r=baku a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D42092
dom/fetch/FetchDriver.cpp
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -820,17 +820,22 @@ FetchDriver::OnStartRequest(nsIRequest* 
   aRequest->GetStatus(&rv);
   if (NS_FAILED(rv)) {
     FailWithNetworkError(rv);
     return rv;
   }
 
   // We should only get to the following code once.
   MOZ_ASSERT(!mPipeOutputStream);
-  MOZ_ASSERT(mObserver);
+
+  if (!mObserver) {
+    MOZ_ASSERT(false, "We should have mObserver here.");
+    FailWithNetworkError(NS_ERROR_UNEXPECTED);
+    return NS_ERROR_UNEXPECTED;
+  }
 
   mNeedToObserveOnDataAvailable = mObserver->NeedOnDataAvailable();
 
   RefPtr<InternalResponse> response;
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
 
   // On a successful redirect we perform the following substeps of HTTP Fetch,
@@ -1467,16 +1472,18 @@ void FetchDriver::SetRequestHeaders(nsIH
           nsDependentCString(net::nsHttp::Origin),
           NS_ConvertUTF16toUTF8(origin), false /* merge */);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
   }
 }
 
 void FetchDriver::Abort() {
+  MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
+
   if (mObserver) {
 #ifdef DEBUG
     mResponseAvailableCalled = true;
 #endif
     mObserver->OnResponseEnd(FetchDriverObserver::eAborted);
     mObserver = nullptr;
   }