Bug 1403771 - don't clone m_inputStream since it will never close. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Sat, 07 Oct 2017 22:01:01 +0200
changeset 29123 3d4d669c055763b5a4f8973084cc881c88c08beb
parent 29122 f894d93fe2d7741c15d2595128957a1ef7473864
child 29124 48a4c3f584cc13bef1fc1c405c7edb312dc7995e
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1403771
Bug 1403771 - don't clone m_inputStream since it will never close. rs=bustage-fix
mailnews/base/util/nsMsgProtocol.cpp
--- a/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mailnews/base/util/nsMsgProtocol.cpp
@@ -37,17 +37,16 @@
 #include "nsIInputStreamPump.h"
 #include "nsICancelable.h"
 #include "nsMimeTypes.h"
 #include "nsAlgorithm.h"
 #include "mozilla/Services.h"
 #include <algorithm>
 #include "nsContentSecurityManager.h"
 #include "SlicedInputStream.h"
-#include "nsStreamUtils.h"
 
 #undef PostMessage // avoid to collision with WinUser.h
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS(nsMsgProtocol, nsIChannel, nsIStreamListener,
   nsIRequestObserver, nsIRequest, nsITransportEventSink)
 
@@ -471,33 +470,23 @@ nsresult nsMsgProtocol::LoadUrl(nsIURI *
           if (NS_FAILED(rv)) return rv;
         }
 
         int64_t offset = 0;
         nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(m_inputStream));
         if (seekable && NS_FAILED(seekable->Tell(&offset))) {
           offset = 0;
         }
-        nsCOMPtr<nsIInputStream> clonedStream;
-        nsCOMPtr<nsIInputStream> replacementStream;
-        rv = NS_CloneInputStream(m_inputStream,
-                                 getter_AddRefs(clonedStream),
-                                 getter_AddRefs(replacementStream));
-        NS_ENSURE_SUCCESS(rv, rv);
-        if (replacementStream) {
-          // If m_inputStream is not cloneable, NS_CloneInputStream will clone
-          // it using a pipe. In order to keep the copy alive and working, we
-          // have to replace the original stream with the replacement.
-          m_inputStream = replacementStream.forget();
-        }
 
         // m_readCount can be -1 which means "read as much as we can".
         // We pass this on as UINT64_MAX, which is in fact uint64_t(-1).
+        // We don't clone m_inputStream here, we simply give up ownership
+        // since otherwise the original would never be closed.
         RefPtr<SlicedInputStream> slicedStream =
-          new SlicedInputStream(clonedStream.forget(), uint64_t(offset),
+          new SlicedInputStream(m_inputStream.forget(), uint64_t(offset),
                                 m_readCount == -1 ? UINT64_MAX : uint64_t(m_readCount));
         nsCOMPtr<nsIInputStreamPump> pump;
         rv = NS_NewInputStreamPump(getter_AddRefs(pump), slicedStream);
         if (NS_FAILED(rv)) return rv;
 
         m_request = pump; // keep a reference to the pump so we can cancel it
 
         // put us in a state where we are always notified of incoming data