Bug 708935 - Make the DNS listener proxies release the nsIDNSListener on the main thread, to solve last-release issues and ASSERTION: ASSERTION: nsStandardURL not thread-safe from PendingPACQuery, r=mcmanus
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 30 Dec 2011 12:53:44 -0500
changeset 83582 fca43c453bc4010b5a5c48cb1e6434b3486d768a
parent 83581 c85e6c648d8f4490001317f738e786303cc25dd4
child 83583 aa47e51cbd8a84409b36979c6adae620a413a2e7
push idunknown
push userunknown
push dateunknown
reviewersmcmanus
bugs708935
milestone12.0a1
Bug 708935 - Make the DNS listener proxies release the nsIDNSListener on the main thread, to solve last-release issues and ASSERTION: ASSERTION: nsStandardURL not thread-safe from PendingPACQuery, r=mcmanus
netwerk/dns/nsDNSService2.cpp
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -38,16 +38,17 @@
 #include "nsDNSService2.h"
 #include "nsIDNSRecord.h"
 #include "nsIDNSListener.h"
 #include "nsICancelable.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefBranch2.h"
 #include "nsIServiceManager.h"
+#include "nsProxyRelease.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "nsNetCID.h"
 #include "nsNetError.h"
 #include "nsDNSPrefetch.h"
 #include "nsThreadUtils.h"
 #include "nsIProtocolProxyService.h"
@@ -480,32 +481,44 @@ namespace {
 class DNSListenerProxy : public nsIDNSListener
 {
 public:
   DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
     : mListener(aListener)
     , mTargetThread(aTargetThread)
   { }
 
+  ~DNSListenerProxy()
+  {
+    nsCOMPtr<nsIThread> mainThread(do_GetMainThread());
+    NS_ProxyRelease(mainThread, mListener);
+  }
+
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDNSLISTENER
 
   class OnLookupCompleteRunnable : public nsRunnable
   {
   public:
     OnLookupCompleteRunnable(nsIDNSListener* aListener,
                              nsICancelable* aRequest,
                              nsIDNSRecord* aRecord,
                              nsresult aStatus)
       : mListener(aListener)
       , mRequest(aRequest)
       , mRecord(aRecord)
       , mStatus(aStatus)
     { }
 
+    ~OnLookupCompleteRunnable()
+    {
+      nsCOMPtr<nsIThread> mainThread(do_GetMainThread());
+      NS_ProxyRelease(mainThread, mListener);
+    }
+
     NS_DECL_NSIRUNNABLE
 
   private:
     nsCOMPtr<nsIDNSListener> mListener;
     nsCOMPtr<nsICancelable> mRequest;
     nsCOMPtr<nsIDNSRecord> mRecord;
     nsresult mStatus;
   };