Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1577311 - Close the stream if there is a failure during the creat…
Browse files Browse the repository at this point in the history
…ion; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D47118
  • Loading branch information
chihweitung committed Oct 2, 2019
1 parent 0638c67 commit 9bb61a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dom/base/BodyStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void BodyStreamHolder::StoreBodyStream(BodyStream* aBodyStream) {
}

void BodyStreamHolder::ForgetBodyStream() {
MOZ_ASSERT(mBodyStream);
MOZ_ASSERT_IF(mStreamCreated, mBodyStream);
mBodyStream = nullptr;
}

Expand Down Expand Up @@ -92,6 +92,8 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
RefPtr<BodyStream> stream =
new BodyStream(aGlobal, aStreamHolder, aInputStream);

auto cleanup = MakeScopeExit([stream] { stream->Close(); });

if (NS_IsMainThread()) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (NS_WARN_IF(!os)) {
Expand Down Expand Up @@ -135,8 +137,14 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
// js object is finalized.
NS_ADDREF(stream.get());

cleanup.release();

aStreamHolder->StoreBodyStream(stream);
aStreamHolder->SetReadableStreamBody(body);

#ifdef DEBUG
aStreamHolder->mStreamCreated = true;
#endif
}

void BodyStream::requestData(JSContext* aCx, JS::HandleObject aStream,
Expand Down
4 changes: 4 additions & 0 deletions dom/base/BodyStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class BodyStreamHolder : public nsISupports {
// Raw pointer because BodyStream keeps BodyStreamHolder alive and it
// nullifies this stream before being released.
BodyStream* mBodyStream;

#ifdef DEBUG
bool mStreamCreated = false;
#endif
};

class BodyStream final : public nsIInputStreamCallback,
Expand Down

0 comments on commit 9bb61a6

Please sign in to comment.