From 1920aae3dcae94b4797e048b9a4924448dc5e1d2 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Tue, 9 Nov 2021 21:08:53 +0800 Subject: [PATCH] Bug 1735152 - Avoid using NS_ADDREF in nsSocketTransport. r=dragana, a=RyanVM --- netwerk/base/nsSocketTransport2.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp index 1d3d58866b..6ccf2f1077 100644 --- a/netwerk/base/nsSocketTransport2.cpp +++ b/netwerk/base/nsSocketTransport2.cpp @@ -1,5 +1,4 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:set ts=4 sw=4 et cindent: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -2115,7 +2114,7 @@ NS_IMETHODIMP nsSocketTransport::OpenInputStream(uint32_t flags, uint32_t segsize, uint32_t segcount, - nsIInputStream **result) + nsIInputStream **aResult) { SOCKET_LOG(("nsSocketTransport::OpenInputStream [this=%p flags=%x]\n", this, flags)); @@ -2124,6 +2123,7 @@ nsSocketTransport::OpenInputStream(uint32_t flags, nsresult rv; nsCOMPtr pipeIn; + nsCOMPtr result; if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { // XXX if the caller wants blocking, then the caller also gets buffered! @@ -2143,18 +2143,20 @@ nsSocketTransport::OpenInputStream(uint32_t flags, NS_ASYNCCOPY_VIA_WRITESEGMENTS, segsize); if (NS_FAILED(rv)) return rv; - *result = pipeIn; + result = pipeIn; } else - *result = &mInput; + result = &mInput; // flag input stream as open mInputClosed = false; rv = PostEvent(MSG_ENSURE_CONNECT); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } - NS_ADDREF(*result); + result.forget(aResult); return NS_OK; } @@ -2162,7 +2164,7 @@ NS_IMETHODIMP nsSocketTransport::OpenOutputStream(uint32_t flags, uint32_t segsize, uint32_t segcount, - nsIOutputStream **result) + nsIOutputStream **aResult) { SOCKET_LOG(("nsSocketTransport::OpenOutputStream [this=%p flags=%x]\n", this, flags)); @@ -2171,6 +2173,8 @@ nsSocketTransport::OpenOutputStream(uint32_t flags, nsresult rv; nsCOMPtr pipeOut; + nsCOMPtr result; + if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { // XXX if the caller wants blocking, then the caller also gets buffered! //bool openBuffered = !(flags & OPEN_UNBUFFERED); @@ -2189,10 +2193,10 @@ nsSocketTransport::OpenOutputStream(uint32_t flags, NS_ASYNCCOPY_VIA_READSEGMENTS, segsize); if (NS_FAILED(rv)) return rv; - *result = pipeOut; + result = pipeOut; } else - *result = &mOutput; + result = &mOutput; // flag output stream as open mOutputClosed = false; @@ -2200,7 +2204,7 @@ nsSocketTransport::OpenOutputStream(uint32_t flags, rv = PostEvent(MSG_ENSURE_CONNECT); if (NS_FAILED(rv)) return rv; - NS_ADDREF(*result); + result.forget(aResult); return NS_OK; }