Bug 1471435 - part 1 - clean up nsFile{Input,Ouput}Stream::Create; r=valentin
authorNathan Froyd <froydnj@mozilla.com>
Wed, 27 Jun 2018 11:27:33 -0400
changeset 423943 14b77f98e81c7bfb5520e9ca38c6bc280dbf08fa
parent 423942 1b9dcb1b80dd3f906ab4f59556afe32b71c51d12
child 423944 f0b7524a7081602558bd66415fec3a98f98073ae
push id34196
push usertoros@mozilla.com
push dateWed, 27 Jun 2018 22:08:08 +0000
treeherdermozilla-central@f8acdf0185d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1471435
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471435 - part 1 - clean up nsFile{Input,Ouput}Stream::Create; r=valentin We should be using smart pointers here, and there's no need to check for allocation failure with our infallible new policy.
netwerk/base/nsFileStreams.cpp
--- a/netwerk/base/nsFileStreams.cpp
+++ b/netwerk/base/nsFileStreams.cpp
@@ -444,23 +444,18 @@ NS_IMPL_CI_INTERFACE_GETTER(nsFileInputS
                             nsISeekableStream,
                             nsILineInputStream)
 
 nsresult
 nsFileInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 {
     NS_ENSURE_NO_AGGREGATION(aOuter);
 
-    nsFileInputStream* stream = new nsFileInputStream();
-    if (stream == nullptr)
-        return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(stream);
-    nsresult rv = stream->QueryInterface(aIID, aResult);
-    NS_RELEASE(stream);
-    return rv;
+    RefPtr<nsFileInputStream> stream = new nsFileInputStream();
+    return stream->QueryInterface(aIID, aResult);
 }
 
 nsresult
 nsFileInputStream::Open(nsIFile* aFile, int32_t aIOFlags, int32_t aPerm)
 {
     nsresult rv = NS_OK;
 
     // If the previous file is open, close it
@@ -722,23 +717,18 @@ NS_IMPL_ISUPPORTS_INHERITED(nsFileOutput
                             nsIOutputStream,
                             nsIFileOutputStream)
 
 nsresult
 nsFileOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 {
     NS_ENSURE_NO_AGGREGATION(aOuter);
 
-    nsFileOutputStream* stream = new nsFileOutputStream();
-    if (stream == nullptr)
-        return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(stream);
-    nsresult rv = stream->QueryInterface(aIID, aResult);
-    NS_RELEASE(stream);
-    return rv;
+    RefPtr<nsFileOutputStream> stream = new nsFileOutputStream();
+    return stream->QueryInterface(aIID, aResult);
 }
 
 NS_IMETHODIMP
 nsFileOutputStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
                          int32_t behaviorFlags)
 {
     NS_ENSURE_TRUE(mFD == nullptr, NS_ERROR_ALREADY_INITIALIZED);
     NS_ENSURE_TRUE(mState == eUnitialized || mState == eClosed,