From 6b9905351219d914fd2aa218338fc44b028020e1 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 18 Mar 2013 20:39:53 -0700 Subject: [PATCH] Bug 850245 - Remove Off-Main-Thread XPCWrappedJS refcounting from DNSListenerProxy. r=mcmanus --- netwerk/dns/nsDNSService2.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/netwerk/dns/nsDNSService2.cpp b/netwerk/dns/nsDNSService2.cpp index dd951481e0f..f85bafc8303 100644 --- a/netwerk/dns/nsDNSService2.cpp +++ b/netwerk/dns/nsDNSService2.cpp @@ -27,6 +27,7 @@ #include "nsIOService.h" #include "nsCharSeparatedTokenizer.h" #include "nsNetAddr.h" +#include "nsProxyRelease.h" #include "mozilla/Attributes.h" @@ -516,23 +517,21 @@ class DNSListenerProxy MOZ_FINAL : public nsIDNSListener { public: DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread) - : mListener(aListener) + // Sometimes aListener is a main-thread only object like XPCWrappedJS, and + // sometimes it's a threadsafe object like nsSOCKSSocketInfo. Use a main- + // thread pointer holder, but disable strict enforcement of thread invariants. + // The AddRef implementation of XPCWrappedJS will assert if we go wrong here. + : mListener(new nsMainThreadPtrHolder(aListener, false)) , mTargetThread(aTargetThread) { } - ~DNSListenerProxy() - { - nsCOMPtr mainThread(do_GetMainThread()); - NS_ProxyRelease(mainThread, mListener); - } - NS_DECL_ISUPPORTS NS_DECL_NSIDNSLISTENER class OnLookupCompleteRunnable : public nsRunnable { public: - OnLookupCompleteRunnable(nsIDNSListener* aListener, + OnLookupCompleteRunnable(nsMainThreadPtrHolder* aListener, nsICancelable* aRequest, nsIDNSRecord* aRecord, nsresult aStatus) @@ -542,23 +541,17 @@ public: , mStatus(aStatus) { } - ~OnLookupCompleteRunnable() - { - nsCOMPtr mainThread(do_GetMainThread()); - NS_ProxyRelease(mainThread, mListener); - } - NS_DECL_NSIRUNNABLE private: - nsCOMPtr mListener; + nsMainThreadPtrHandle mListener; nsCOMPtr mRequest; nsCOMPtr mRecord; nsresult mStatus; }; private: - nsCOMPtr mListener; + nsMainThreadPtrHandle mListener; nsCOMPtr mTargetThread; };