Bug 716293 - release sink on the same thread where the data is written
authorMichal Novotny <michal.novotny@gmail.com>
Wed, 11 Jan 2012 18:18:25 +0100
changeset 85522 dc23947abad9e1246bd9c281b3ce518a38f4e042
parent 85521 81cb240e14c4fac784678b5354c51e7836ea096a
child 85523 39b93b408124b4362ebcc8aed34a97d46210bc30
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs716293
milestone12.0a1
Bug 716293 - release sink on the same thread where the data is written
netwerk/base/src/nsStreamListenerTee.cpp
--- a/netwerk/base/src/nsStreamListenerTee.cpp
+++ b/netwerk/base/src/nsStreamListenerTee.cpp
@@ -31,16 +31,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsStreamListenerTee.h"
+#include "nsProxyRelease.h"
 
 NS_IMPL_ISUPPORTS3(nsStreamListenerTee,
                    nsIStreamListener,
                    nsIRequestObserver,
                    nsIStreamListenerTee)
 
 NS_IMETHODIMP
 nsStreamListenerTee::OnStartRequest(nsIRequest *request,
@@ -62,17 +63,27 @@ nsStreamListenerTee::OnStopRequest(nsIRe
                                    nsresult status)
 {
     NS_ENSURE_TRUE(mListener, NS_ERROR_NOT_INITIALIZED);
     // it is critical that we close out the input stream tee
     if (mInputTee) {
         mInputTee->SetSink(nsnull);
         mInputTee = 0;
     }
-    mSink = 0;
+
+    // release sink on the same thread where the data was written (bug 716293)
+    if (mEventTarget) {
+        nsIOutputStream *sink = nsnull;
+        mSink.swap(sink);
+        NS_ProxyRelease(mEventTarget, sink);
+    }
+    else {
+        mSink = 0;
+    }
+
     nsresult rv = mListener->OnStopRequest(request, context, status);
     if (mObserver)
         mObserver->OnStopRequest(request, context, status);
     mObserver = 0;
     return rv;
 }
 
 NS_IMETHODIMP