From aa6fe46883f94ac174050480db54ccb6ffdccd0a Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Thu, 25 Jan 2024 17:18:48 +0000 Subject: [PATCH] Bug 1843752 - Explicitly transfer ownership of queued-up OnDataAvailableParams data buffers, r=necko-reviewers,kershaw Differential Revision: https://phabricator.services.mozilla.com/D198189 --- netwerk/ipc/DocumentLoadListener.cpp | 4 ++-- netwerk/ipc/NeckoCommon.cpp | 18 ++++++++---------- netwerk/ipc/NeckoCommon.h | 4 ++-- netwerk/protocol/http/EarlyHintPreloader.cpp | 6 +++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 79726bc27e03..47b042a422fc 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -1470,7 +1470,7 @@ bool DocumentLoadListener::ResumeSuspendedChannel( streamListenerFunctions.Clear(); } - ForwardStreamListenerFunctions(streamListenerFunctions, aListener); + ForwardStreamListenerFunctions(std::move(streamListenerFunctions), aListener); // We don't expect to get new stream listener functions added // via re-entrancy. If this ever happens, we should understand @@ -2703,7 +2703,7 @@ DocumentLoadListener::OnDataAvailable(nsIRequest* aRequest, mStreamListenerFunctions.AppendElement(StreamListenerFunction{ VariantIndex<1>{}, - OnDataAvailableParams{aRequest, data, aOffset, aCount}}); + OnDataAvailableParams{aRequest, std::move(data), aOffset, aCount}}); return NS_OK; } diff --git a/netwerk/ipc/NeckoCommon.cpp b/netwerk/ipc/NeckoCommon.cpp index c08faa5747f8..9ad4483d3226 100644 --- a/netwerk/ipc/NeckoCommon.cpp +++ b/netwerk/ipc/NeckoCommon.cpp @@ -14,28 +14,26 @@ namespace mozilla::net { -nsresult ForwardStreamListenerFunctions( - nsTArray& aCalls, nsIStreamListener* aParent) { +nsresult ForwardStreamListenerFunctions(nsTArray aCalls, + nsIStreamListener* aParent) { nsresult rv = NS_OK; for (auto& variant : aCalls) { variant.match( - [&](const OnStartRequestParams& aParams) { + [&](OnStartRequestParams& aParams) { rv = aParent->OnStartRequest(aParams.request); if (NS_FAILED(rv)) { aParams.request->Cancel(rv); } }, - [&](const OnDataAvailableParams& aParams) { + [&](OnDataAvailableParams& aParams) { // Don't deliver OnDataAvailable if we've // already failed. if (NS_FAILED(rv)) { return; } nsCOMPtr stringStream; - rv = NS_NewByteInputStream( - getter_AddRefs(stringStream), - Span(aParams.data.get(), aParams.count), - NS_ASSIGNMENT_DEPEND); + rv = NS_NewCStringInputStream(getter_AddRefs(stringStream), + std::move(aParams.data)); if (NS_SUCCEEDED(rv)) { rv = aParent->OnDataAvailable(aParams.request, stringStream, aParams.offset, aParams.count); @@ -44,7 +42,7 @@ nsresult ForwardStreamListenerFunctions( aParams.request->Cancel(rv); } }, - [&](const OnStopRequestParams& aParams) { + [&](OnStopRequestParams& aParams) { if (NS_SUCCEEDED(rv)) { aParent->OnStopRequest(aParams.request, aParams.status); } else { @@ -52,7 +50,7 @@ nsresult ForwardStreamListenerFunctions( } rv = NS_OK; }, - [&](const OnAfterLastPartParams& aParams) { + [&](OnAfterLastPartParams& aParams) { nsCOMPtr multiListener = do_QueryInterface(aParent); if (multiListener) { diff --git a/netwerk/ipc/NeckoCommon.h b/netwerk/ipc/NeckoCommon.h index 6f63ef1b2a82..57f770db68a4 100644 --- a/netwerk/ipc/NeckoCommon.h +++ b/netwerk/ipc/NeckoCommon.h @@ -135,8 +135,8 @@ using StreamListenerFunction = mozilla::Variant; -nsresult ForwardStreamListenerFunctions( - nsTArray& aCalls, nsIStreamListener* aParent); +nsresult ForwardStreamListenerFunctions(nsTArray aCalls, + nsIStreamListener* aParent); } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/EarlyHintPreloader.cpp b/netwerk/protocol/http/EarlyHintPreloader.cpp index 60db1b1ca33d..94abe1574aea 100644 --- a/netwerk/protocol/http/EarlyHintPreloader.cpp +++ b/netwerk/protocol/http/EarlyHintPreloader.cpp @@ -582,7 +582,7 @@ void EarlyHintPreloader::InvokeStreamListenerFunctions() { nsTArray streamListenerFunctions = std::move(mStreamListenerFunctions); - ForwardStreamListenerFunctions(streamListenerFunctions, mParent); + ForwardStreamListenerFunctions(std::move(streamListenerFunctions), mParent); // We don't expect to get new stream listener functions added // via re-entrancy. If this ever happens, we should understand @@ -696,8 +696,8 @@ EarlyHintPreloader::OnDataAvailable(nsIRequest* aRequest, nsresult rv = NS_ReadInputStreamToString(aInputStream, data, aCount); NS_ENSURE_SUCCESS(rv, rv); - mStreamListenerFunctions.AppendElement( - AsVariant(OnDataAvailableParams{aRequest, data, aOffset, aCount})); + mStreamListenerFunctions.AppendElement(AsVariant( + OnDataAvailableParams{aRequest, std::move(data), aOffset, aCount})); return NS_OK; }