From c3778db14df34e88bfd3663b2b3fb54ead633402 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 21 Oct 2020 20:35:07 +0000 Subject: [DOM Fetch] Improve stability of Fetch API. --- dom/fetch/FetchDriver.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index fd1e99a2b..d028ffdba 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -709,10 +709,12 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest, // about races. if (mObserver) { + // Need to keep mObserver alive. + RefPtr observer = mObserver; if (NS_IsMainThread()) { - mObserver->OnDataAvailable(); + observer->OnDataAvailable(); } else { - RefPtr runnable = new DataAvailableRunnable(mObserver); + RefPtr runnable = new DataAvailableRunnable(observer); nsresult rv = NS_DispatchToMainThread(runnable); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -720,12 +722,15 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest, } } - uint32_t aRead; + // Explicitly initialized to 0 because in some cases nsStringInputStream may + // not write to aRead. + uint32_t aRead = 0; MOZ_ASSERT(mResponse); MOZ_ASSERT(mPipeOutputStream); // From "Main Fetch" step 17: SRI-part2. - if (mResponse->Type() != ResponseType::Error && + if (mResponse && + mResponse->Type() != ResponseType::Error && !mRequest->GetIntegrity().IsEmpty()) { MOZ_ASSERT(mSRIDataVerifier); -- cgit v1.2.3