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 523454 5386529d27f4f2f9ce53a042ec82439c84c90052
parent 523453 134cc7161f236e02dc9e1f2a068c5182c413e531
child 523455 18bcc03292a53b74e7e08c8534563da4b9075cbf
push id255
push userarchaeopteryx@coole-files.de
push dateWed, 21 Aug 2019 23:26:31 +0000
treeherdermozilla-esr68@d574e9e14ca2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, RyanVM
bugs1571283
milestone68.1.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
@@ -818,17 +818,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,
@@ -1465,16 +1470,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;
   }