Backed out changeset 03e4f9175b16 (bug 1409329)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 17 Oct 2017 22:03:39 +0200
changeset 386827 ec2f3cbc85809e0d9937383f1a0db0750dd9ed1f
parent 386826 cb8c65940190581eb878f9999ae71a50d9fec873
child 386828 a461a81095f8b734427f244e1bb7e09d53713e65
push id32702
push userarchaeopteryx@coole-files.de
push dateWed, 18 Oct 2017 09:48:58 +0000
treeherdermozilla-central@a29052590fc6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1409329
milestone58.0a1
backs out03e4f9175b16ef4a89b1371c15c62ea637aa545e
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
Backed out changeset 03e4f9175b16 (bug 1409329)
dom/webbrowserpersist/nsWebBrowserPersist.cpp
dom/workers/ServiceWorkerEvents.cpp
extensions/spellcheck/src/mozPersonalDictionary.cpp
modules/libjar/zipwriter/nsZipWriter.cpp
modules/libpref/Preferences.cpp
netwerk/base/BackgroundFileSaver.cpp
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
netwerk/cache/nsDiskCacheDeviceSQL.cpp
rdf/base/nsRDFXMLDataSource.cpp
security/manager/ssl/nsCertOverrideService.cpp
toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
--- a/dom/webbrowserpersist/nsWebBrowserPersist.cpp
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.cpp
@@ -2316,19 +2316,18 @@ nsWebBrowserPersist::MakeOutputStreamFro
 
     // XXX brade:  get the right flags here!
     int32_t ioFlags = -1;
     if (mPersistFlags & nsIWebBrowserPersist::PERSIST_FLAGS_APPEND_TO_FILE)
       ioFlags = PR_APPEND | PR_CREATE_FILE | PR_WRONLY;
     rv = fileOutputStream->Init(aFile, ioFlags, -1, 0);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = NS_NewBufferedOutputStream(aOutputStream, fileOutputStream.forget(),
-                                    BUFFERED_OUTPUT_SIZE);
-    NS_ENSURE_SUCCESS(rv, rv);
+    *aOutputStream = NS_BufferOutputStream(fileOutputStream,
+                                           BUFFERED_OUTPUT_SIZE).take();
 
     if (mPersistFlags & PERSIST_FLAGS_CLEANUP_ON_FAILURE)
     {
         // Add to cleanup list in event of failure
         auto *cleanupData = new CleanupData;
         if (!cleanupData) {
           NS_RELEASE(*aOutputStream);
           return NS_ERROR_OUT_OF_MEMORY;
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -659,18 +659,18 @@ RespondWithHandler::ResolvedCallback(JSC
     // get a non-buffered input stream.  In addition, in some configurations the
     // destination channel's output stream can be unbuffered.  We wrap the output
     // stream side here so that NS_AsyncCopy() works.  Wrapping the output side
     // provides the most consistent operation since there are fewer stream types
     // we are writing to.  The input stream can be a wide variety of concrete
     // objects which may or many not play well with NS_InputStreamIsBuffered().
     if (!NS_OutputStreamIsBuffered(responseBody)) {
       nsCOMPtr<nsIOutputStream> buffered;
-      rv = NS_NewBufferedOutputStream(getter_AddRefs(buffered),
-                                      responseBody.forget(), kCopySegmentSize);
+      rv = NS_NewBufferedOutputStream(getter_AddRefs(buffered), responseBody,
+           kCopySegmentSize);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return;
       }
       responseBody = buffered;
     }
 
     nsCOMPtr<nsIEventTarget> stsThread = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
     if (NS_WARN_IF(!stsThread)) {
--- a/extensions/spellcheck/src/mozPersonalDictionary.cpp
+++ b/extensions/spellcheck/src/mozPersonalDictionary.cpp
@@ -100,17 +100,17 @@ public:
       nsCOMPtr<nsIOutputStream> outStream;
       NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStream), mFile,
                                       PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
                                       0664);
 
       // Get a buffered output stream 4096 bytes big, to optimize writes.
       nsCOMPtr<nsIOutputStream> bufferedOutputStream;
       res = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
-                                       outStream.forget(), 4096);
+                                       outStream, 4096);
       if (NS_FAILED(res)) {
         return res;
       }
 
       uint32_t bytesWritten;
       nsAutoCString utf8Key;
       for (uint32_t i = 0; i < mDictWords.Length(); ++i) {
         CopyUTF16toUTF8(mDictWords[i], utf8Key);
--- a/modules/libjar/zipwriter/nsZipWriter.cpp
+++ b/modules/libjar/zipwriter/nsZipWriter.cpp
@@ -265,19 +265,19 @@ NS_IMETHODIMP nsZipWriter::Open(nsIFile 
     nsCOMPtr<nsIOutputStream> stream;
     rv = NS_NewLocalFileOutputStream(getter_AddRefs(stream), mFile, aIoFlags);
     if (NS_FAILED(rv)) {
         mHeaders.Clear();
         mEntryHash.Clear();
         return rv;
     }
 
-    rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream.forget(),
-                                    64 * 1024);
+    rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream, 64 * 1024);
     if (NS_FAILED(rv)) {
+        stream->Close();
         mHeaders.Clear();
         mEntryHash.Clear();
         return rv;
     }
 
     if (mCDSOffset > 0) {
         rv = SeekCDS();
         NS_ENSURE_SUCCESS(rv, rv);
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -3529,17 +3529,17 @@ public:
     // Execute a "safe" save by saving through a tempfile.
     rv = NS_NewSafeLocalFileOutputStream(
       getter_AddRefs(outStreamSink), aFile, -1, 0600);
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     rv = NS_NewBufferedOutputStream(
-      getter_AddRefs(outStream), outStreamSink.forget(), 4096);
+      getter_AddRefs(outStream), outStreamSink, 4096);
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     struct CharComparator
     {
       bool LessThan(const mozilla::UniqueFreePtr<char>& a,
                     const mozilla::UniqueFreePtr<char>& b) const
--- a/netwerk/base/BackgroundFileSaver.cpp
+++ b/netwerk/base/BackgroundFileSaver.cpp
@@ -615,19 +615,20 @@ BackgroundFileSaver::ProcessStateChange(
   // extension. Those part files should never be group or world-writable even
   // if the umask allows it.
   nsCOMPtr<nsIOutputStream> outputStream;
   rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream),
                                    mActualTarget,
                                    PR_WRONLY | creationIoFlags, 0600);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(outputStream),
-                                  outputStream.forget(), BUFFERED_IO_SIZE);
-  NS_ENSURE_SUCCESS(rv, rv);
+  outputStream = NS_BufferOutputStream(outputStream, BUFFERED_IO_SIZE);
+  if (!outputStream) {
+    return NS_ERROR_FAILURE;
+  }
 
   // Wrap the output stream so that it feeds the digest context if needed.
   if (mDigestContext) {
     // No need to acquire the NSS lock here, DigestOutputStream must acquire it
     // in any case before each asynchronous write. Constructing the
     // DigestOutputStream cannot fail. Passing mDigestContext to
     // DigestOutputStream is safe, because BackgroundFileSaver always outlives
     // the outputStream. BackgroundFileSaver is reference-counted before the
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1332,34 +1332,48 @@ NS_NewLocalFileStream(nsIFileStream **re
         rv = stream->Init(file, ioFlags, perm, behaviorFlags);
         if (NS_SUCCEEDED(rv))
             stream.forget(result);
     }
     return rv;
 }
 
 nsresult
-NS_NewBufferedOutputStream(nsIOutputStream** aResult,
-                           already_AddRefed<nsIOutputStream> aOutputStream,
-                           uint32_t aBufferSize)
+NS_NewBufferedOutputStream(nsIOutputStream **result,
+                           nsIOutputStream  *str,
+                           uint32_t          bufferSize)
 {
-    nsCOMPtr<nsIOutputStream> outputStream = Move(aOutputStream);
-
     nsresult rv;
     nsCOMPtr<nsIBufferedOutputStream> out =
         do_CreateInstance(NS_BUFFEREDOUTPUTSTREAM_CONTRACTID, &rv);
     if (NS_SUCCEEDED(rv)) {
-        rv = out->Init(outputStream, aBufferSize);
+        rv = out->Init(str, bufferSize);
         if (NS_SUCCEEDED(rv)) {
-            out.forget(aResult);
+            out.forget(result);
         }
     }
     return rv;
 }
 
+already_AddRefed<nsIOutputStream>
+NS_BufferOutputStream(nsIOutputStream *aOutputStream,
+                      uint32_t aBufferSize)
+{
+    NS_ASSERTION(aOutputStream, "No output stream given!");
+
+    nsCOMPtr<nsIOutputStream> bos;
+    nsresult rv = NS_NewBufferedOutputStream(getter_AddRefs(bos), aOutputStream,
+                                             aBufferSize);
+    if (NS_SUCCEEDED(rv))
+        return bos.forget();
+
+    bos = aOutputStream;
+    return bos.forget();
+}
+
 MOZ_MUST_USE nsresult
 NS_NewBufferedInputStream(nsIInputStream **result,
                           nsIInputStream  *str,
                           uint32_t         bufferSize)
 {
     nsresult rv;
     nsCOMPtr<nsIBufferedInputStream> in =
         do_CreateInstance(NS_BUFFEREDINPUTSTREAM_CONTRACTID, &rv);
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -512,20 +512,34 @@ nsresult NS_NewLocalFileStream(nsIFileSt
 
 MOZ_MUST_USE nsresult
 NS_NewBufferedInputStream(nsIInputStream **result,
                           nsIInputStream  *str,
                           uint32_t         bufferSize);
 
 // note: the resulting stream can be QI'ed to nsISafeOutputStream iff the
 // provided stream supports it.
-nsresult NS_NewBufferedOutputStream(nsIOutputStream** aResult,
-                                    already_AddRefed<nsIOutputStream> aOutputStream,
-                                    uint32_t aBufferSize);
+nsresult NS_NewBufferedOutputStream(nsIOutputStream **result,
+                                    nsIOutputStream  *str,
+                                    uint32_t          bufferSize);
 
+/**
+ * Attempts to buffer a given stream.  If this fails, it returns the
+ * passed-in stream.
+ *
+ * @param aOutputStream
+ *        The output stream we want to buffer.  This cannot be null.
+ * @param aBufferSize
+ *        The size of the buffer for the buffered output stream.
+ * @returns an nsIOutputStream that is buffered with the specified buffer size,
+ *          or is aOutputStream if creating the new buffered stream failed.
+ */
+already_AddRefed<nsIOutputStream>
+NS_BufferOutputStream(nsIOutputStream *aOutputStream,
+                      uint32_t aBufferSize);
 already_AddRefed<nsIInputStream>
 NS_BufferInputStream(nsIInputStream *aInputStream,
                       uint32_t aBufferSize);
 
 // returns an input stream compatible with nsIUploadChannel::SetUploadStream()
 nsresult NS_NewPostDataStream(nsIInputStream  **result,
                               bool              isFile,
                               const nsACString &data);
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -1810,18 +1810,17 @@ nsOfflineCacheDevice::OpenOutputStreamFo
   if (offset != 0)
     seekable->Seek(nsISeekableStream::NS_SEEK_SET, offset);
 
   // truncate the file at the given offset
   seekable->SetEOF();
 
   nsCOMPtr<nsIOutputStream> bufferedOut;
   nsresult rv =
-    NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out.forget(),
-                               16 * 1024);
+    NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 16 * 1024);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bufferedOut.swap(*result);
   return NS_OK;
 }
 
 nsresult
 nsOfflineCacheDevice::GetFileForEntry(nsCacheEntry *entry, nsIFile **result)
--- a/rdf/base/nsRDFXMLDataSource.cpp
+++ b/rdf/base/nsRDFXMLDataSource.cpp
@@ -761,18 +761,17 @@ RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI
             rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),
                                                  file,
                                                  PR_WRONLY | PR_CREATE_FILE,
                                                  /*octal*/ 0666,
                                                  0);
             if (NS_FAILED(rv)) return rv;
 
             nsCOMPtr<nsIOutputStream> bufferedOut;
-            rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut),
-                                            out.forget(), 4096);
+            rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
             if (NS_FAILED(rv)) return rv;
 
             rv = Serialize(bufferedOut);
             if (NS_FAILED(rv)) return rv;
 
             // All went ok. Maybe except for problems in Write(), but the stream detects
             // that for us
             nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(bufferedOut, &rv);
--- a/security/manager/ssl/nsCertOverrideService.cpp
+++ b/security/manager/ssl/nsCertOverrideService.cpp
@@ -276,18 +276,17 @@ nsCertOverrideService::Write(const Mutex
                                        0600);
   if (NS_FAILED(rv)) {
     NS_ERROR("failed to open cert_warn_settings.txt for writing");
     return rv;
   }
 
   // get a buffered output stream 4096 bytes big, to optimize writes
   nsCOMPtr<nsIOutputStream> bufferedOutputStream;
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
-                                  fileOutputStream.forget(), 4096);
+  rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream), fileOutputStream, 4096);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   static const char kHeader[] =
       "# PSM Certificate Override Settings file" NS_LINEBREAK
       "# This is a generated file!  Do not edit." NS_LINEBREAK;
 
--- a/toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
+++ b/toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
@@ -270,20 +270,18 @@ VariableLengthPrefixSet::StoreToFile(nsI
 
     fileSize += mFixedPrefixSet->CalculatePreallocateSize();
     fileSize += CalculatePreallocateSize();
 
     Unused << fos->Preallocate(fileSize);
   }
 
   // Convert to buffered stream
-  nsCOMPtr<nsIOutputStream> out;
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(out), localOutFile.forget(),
-                                  std::min(fileSize, MAX_BUFFER_SIZE));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIOutputStream> out =
+    NS_BufferOutputStream(localOutFile, std::min(fileSize, MAX_BUFFER_SIZE));
 
   rv = mFixedPrefixSet->WritePrefixes(out);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = WritePrefixes(out);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -380,20 +380,18 @@ nsUrlClassifierPrefixSet::StoreToFile(ns
     fileSize = CalculatePreallocateSize();
 
     // Ignore failure, the preallocation is a hint and we write out the entire
     // file later on
     Unused << fos->Preallocate(fileSize);
   }
 
   // Convert to buffered stream
-  nsCOMPtr<nsIOutputStream> out;
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(out), localOutFile.forget(),
-                                  std::min(fileSize, MAX_BUFFER_SIZE));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIOutputStream> out =
+    NS_BufferOutputStream(localOutFile, std::min(fileSize, MAX_BUFFER_SIZE));
 
   rv = WritePrefixes(out);
   NS_ENSURE_SUCCESS(rv, rv);
 
   LOG(("Saving PrefixSet successful\n"));
 
   return NS_OK;
 }