diff --git a/dom/fetch/FetchConsumer.cpp b/dom/fetch/FetchConsumer.cpp index b3150825ab52..ae3f1b114859 100644 --- a/dom/fetch/FetchConsumer.cpp +++ b/dom/fetch/FetchConsumer.cpp @@ -568,6 +568,11 @@ FetchBodyConsumer::ContinueConsumeBody(nsresult aStatus, { AssertIsOnTargetThread(); + // This makes sure that we free the data correctly. + auto autoFree = mozilla::MakeScopeExit([&] { + free(aResult); + }); + if (mBodyConsumed) { return; } @@ -583,7 +588,6 @@ FetchBodyConsumer::ContinueConsumeBody(nsresult aStatus, RefPtr> self = this; auto autoReleaseObject = mozilla::MakeScopeExit([&] { self->ReleaseObject(); - free(aResult); }); if (aShuttingDown) { @@ -750,6 +754,7 @@ void FetchBodyConsumer::Abort() { AssertIsOnTargetThread(); + ShutDownMainThreadConsuming(); ContinueConsumeBody(NS_ERROR_DOM_ABORT_ERR, 0, nullptr); }