Bug 1143651 - don't use CallQueryInterface when the compiler can do the cast for us; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Thu, 12 Mar 2015 13:20:29 -0400
changeset 267142 73d9939c6095a20b5df14ce207ed0e2570d9f6c6
parent 267141 2241412fcca376ece65c40b5dd000c11ee4cc78d
child 267143 93166201fca032157ecb88923a62e8b2e8f9529d
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1143651
milestone40.0a1
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
Bug 1143651 - don't use CallQueryInterface when the compiler can do the cast for us; r=ehsan
docshell/shistory/src/nsSHistory.cpp
dom/base/MultipartFileImpl.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsFrameMessageManager.cpp
dom/base/nsHTMLContentSerializer.cpp
dom/base/nsPlainTextSerializer.cpp
dom/base/nsXHTMLContentSerializer.cpp
dom/base/nsXMLContentSerializer.cpp
dom/html/HTMLInputElement.cpp
dom/xbl/nsXBLContentSink.cpp
dom/xml/nsXMLContentSink.cpp
dom/xul/nsXULCommandDispatcher.cpp
dom/xul/templates/nsXULTemplateQueryProcessorRDF.cpp
image/src/imgTools.cpp
modules/libjar/nsJARURI.cpp
modules/libpref/Preferences.cpp
netwerk/protocol/device/AndroidCaptureProvider.cpp
netwerk/protocol/device/nsDeviceProtocolHandler.cpp
netwerk/protocol/res/nsResProtocolHandler.cpp
security/manager/ssl/src/nsProtectedAuthThread.cpp
xpfe/appshell/nsWindowMediator.cpp
xpfe/components/windowds/nsWindowDataSource.cpp
--- a/docshell/shistory/src/nsSHistory.cpp
+++ b/docshell/shistory/src/nsSHistory.cpp
@@ -1796,23 +1796,20 @@ nsSHistory::SetRootDocShell(nsIDocShell 
 {
   mRootDocShell = aDocShell;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSHistory::GetSHistoryEnumerator(nsISimpleEnumerator** aEnumerator)
 {
-  nsresult status = NS_OK;
-
   NS_ENSURE_ARG_POINTER(aEnumerator);
-  nsSHEnumerator * iterator = new nsSHEnumerator(this);
-  if (iterator && NS_FAILED(status = CallQueryInterface(iterator, aEnumerator)))
-    delete iterator;
-  return status;
+  nsRefPtr<nsSHEnumerator> iterator = new nsSHEnumerator(this);
+  iterator.forget(aEnumerator);
+  return NS_OK;
 }
 
 
 //*****************************************************************************
 //***    nsSHEnumerator: Object Management
 //*****************************************************************************
 
 nsSHEnumerator::nsSHEnumerator(nsSHistory * aSHistory):mIndex(-1)
--- a/dom/base/MultipartFileImpl.cpp
+++ b/dom/base/MultipartFileImpl.cpp
@@ -41,17 +41,18 @@ MultipartFileImpl::GetInternalStream(nsI
 
     rv = blobImpl->GetInternalStream(getter_AddRefs(scratchStream));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = stream->AppendStream(scratchStream);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  return CallQueryInterface(stream, aStream);
+  stream.forget(aStream);
+  return NS_OK;
 }
 
 already_AddRefed<FileImpl>
 MultipartFileImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
                                const nsAString& aContentType,
                                ErrorResult& aRv)
 {
   // If we clamped to nothing we create an empty blob
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -2494,17 +2494,19 @@ nsFrameLoader::CheckAppHasPermission(con
                                 NS_ConvertUTF16toUTF8(aPermission).get());
 }
 
 NS_IMETHODIMP
 nsFrameLoader::GetMessageManager(nsIMessageSender** aManager)
 {
   EnsureMessageManager();
   if (mMessageManager) {
-    CallQueryInterface(mMessageManager, aManager);
+    nsRefPtr<nsFrameMessageManager> mm(mMessageManager);
+    mm.forget(aManager);
+    return NS_OK;
   }
   return NS_OK;
 }
 
 nsresult
 nsFrameLoader::EnsureMessageManager()
 {
   NS_ENSURE_STATE(mOwnerContent);
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -1485,21 +1485,22 @@ MessageManagerReporter::CollectReports(n
 } // namespace dom
 } // namespace mozilla
 
 nsresult
 NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult)
 {
   NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default,
                  NS_ERROR_NOT_AVAILABLE);
-  nsFrameMessageManager* mm = new nsFrameMessageManager(nullptr,
-                                                        nullptr,
-                                                        MM_CHROME | MM_GLOBAL | MM_BROADCASTER);
+  nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
+                                                                 nullptr,
+                                                                 MM_CHROME | MM_GLOBAL | MM_BROADCASTER);
   RegisterStrongMemoryReporter(new MessageManagerReporter());
-  return CallQueryInterface(mm, aResult);
+  mm.forget(aResult);
+  return NS_OK;
 }
 
 nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>*
   nsMessageManagerScriptExecutor::sCachedScripts = nullptr;
 nsScriptCacheCleaner* nsMessageManagerScriptExecutor::sScriptCacheCleaner = nullptr;
 
 void
 nsMessageManagerScriptExecutor::DidCreateGlobal()
@@ -2003,17 +2004,18 @@ NS_NewParentProcessMessageManager(nsIMes
 {
   NS_ASSERTION(!nsFrameMessageManager::sParentProcessManager,
                "Re-creating sParentProcessManager");
   nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
                                                                  nullptr,
                                                                  MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER);
   nsFrameMessageManager::sParentProcessManager = mm;
   nsFrameMessageManager::NewProcessMessageManager(false); // Create same process message manager.
-  return CallQueryInterface(mm, aResult);
+  mm.forget(aResult);
+  return NS_OK;
 }
 
 
 nsFrameMessageManager*
 nsFrameMessageManager::NewProcessMessageManager(bool aIsRemote)
 {
   if (!nsFrameMessageManager::sParentProcessManager) {
      nsCOMPtr<nsIMessageBroadcaster> dummy =
@@ -2050,19 +2052,20 @@ NS_NewChildProcessMessageManager(nsISync
   } else {
     cb = new ChildProcessMessageManagerCallback();
     RegisterStrongMemoryReporter(new MessageManagerReporter());
   }
   nsFrameMessageManager* mm = new nsFrameMessageManager(cb,
                                                         nullptr,
                                                         MM_PROCESSMANAGER | MM_OWNSCALLBACK);
   nsFrameMessageManager::SetChildProcessManager(mm);
-  ProcessGlobal* global = new ProcessGlobal(mm);
+  nsRefPtr<ProcessGlobal> global = new ProcessGlobal(mm);
   NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED);
-  return CallQueryInterface(global, aResult);
+  global.forget(aResult);
+  return NS_OK;
 
 }
 
 static PLDHashOperator
 CycleCollectorMarkListeners(const nsAString& aKey,
                             nsAutoTObserverArray<nsMessageListenerInfo, 1>* aListeners,
                             void* aData)
 {
--- a/dom/base/nsHTMLContentSerializer.cpp
+++ b/dom/base/nsHTMLContentSerializer.cpp
@@ -35,24 +35,22 @@
 #include "nsIDocShell.h"
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
 #include "mozilla/dom/Element.h"
 #include "nsParserConstants.h"
 
 using namespace mozilla::dom;
 
-nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
+nsresult
+NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
 {
-  nsHTMLContentSerializer* it = new nsHTMLContentSerializer();
-  if (!it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return CallQueryInterface(it, aSerializer);
+  nsRefPtr<nsHTMLContentSerializer> it = new nsHTMLContentSerializer();
+  it.forget(aSerializer);
+  return NS_OK;
 }
 
 nsHTMLContentSerializer::nsHTMLContentSerializer()
 {
     mIsHTMLSerializer = true;
 }
 
 nsHTMLContentSerializer::~nsHTMLContentSerializer()
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -49,24 +49,22 @@ static const  char16_t kSPACE = ' ';
 static int32_t HeaderLevel(nsIAtom* aTag);
 static int32_t GetUnicharWidth(char16_t ucs);
 static int32_t GetUnicharStringWidth(const char16_t* pwcs, int32_t n);
 
 // Someday may want to make this non-const:
 static const uint32_t TagStackSize = 500;
 static const uint32_t OLStackSize = 100;
 
-nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer)
+nsresult
+NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer)
 {
-  nsPlainTextSerializer* it = new nsPlainTextSerializer();
-  if (!it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return CallQueryInterface(it, aSerializer);
+  nsRefPtr<nsPlainTextSerializer> it = new nsPlainTextSerializer();
+  it.forget(aSerializer);
+  return NS_OK;
 }
 
 nsPlainTextSerializer::nsPlainTextSerializer()
   : kSpace(NS_LITERAL_STRING(" ")) // Init of "constant"
 {
 
   mOutputString = nullptr;
   mHeadLevel = 0;
--- a/dom/base/nsXHTMLContentSerializer.cpp
+++ b/dom/base/nsXHTMLContentSerializer.cpp
@@ -35,24 +35,22 @@
 #include "nsParserConstants.h"
 #include "nsComputedDOMStyle.h"
 #include "mozilla/dom/Element.h"
 
 static const int32_t kLongLineLen = 128;
 
 #define kXMLNS "xmlns"
 
-nsresult NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer)
+nsresult
+NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer)
 {
-  nsXHTMLContentSerializer* it = new nsXHTMLContentSerializer();
-  if (!it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return CallQueryInterface(it, aSerializer);
+  nsRefPtr<nsXHTMLContentSerializer> it = new nsXHTMLContentSerializer();
+  it.forget(aSerializer);
+  return NS_OK;
 }
 
 nsXHTMLContentSerializer::nsXHTMLContentSerializer()
   : mIsHTMLSerializer(false)
 {
 }
 
 nsXHTMLContentSerializer::~nsXHTMLContentSerializer()
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -38,24 +38,22 @@ using namespace mozilla::dom;
 // at least this number of characters (arbitrary value here).
 // This is a limit for the indentation.
 #define MIN_INDENTED_LINE_LENGTH 15
 
 // the string used to indent.
 #define INDENT_STRING "  "
 #define INDENT_STRING_LENGTH 2
 
-nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer)
+nsresult
+NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer)
 {
-  nsXMLContentSerializer* it = new nsXMLContentSerializer();
-  if (!it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return CallQueryInterface(it, aSerializer);
+  nsRefPtr<nsXMLContentSerializer> it = new nsXMLContentSerializer();
+  it.forget(aSerializer);
+  return NS_OK;
 }
 
 nsXMLContentSerializer::nsXMLContentSerializer()
   : mPrefixIndex(0),
     mColPos(0),
     mIndentOverflow(0),
     mIsIndentationAddedOnCurrentLine(false),
     mInAttribute(false),
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1905,17 +1905,17 @@ HTMLInputElement::GetList(nsIDOMHTMLElem
 {
   *aValue = nullptr;
 
   nsRefPtr<nsGenericHTMLElement> element = GetList();
   if (!element) {
     return NS_OK;
   }
 
-  CallQueryInterface(element, aValue);
+  element.forget(aValue);
   return NS_OK;
 }
 
 void
 HTMLInputElement::SetValue(Decimal aValue)
 {
   MOZ_ASSERT(!aValue.isInfinity(), "aValue must not be Infinity!");
 
--- a/dom/xbl/nsXBLContentSink.cpp
+++ b/dom/xbl/nsXBLContentSink.cpp
@@ -33,23 +33,22 @@ using namespace mozilla::dom;
 nsresult
 NS_NewXBLContentSink(nsIXMLContentSink** aResult,
                      nsIDocument* aDoc,
                      nsIURI* aURI,
                      nsISupports* aContainer)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
-  nsXBLContentSink* it = new nsXBLContentSink();
-
-  nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
+  nsRefPtr<nsXBLContentSink> it = new nsXBLContentSink();
   nsresult rv = it->Init(aDoc, aURI, aContainer);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return CallQueryInterface(it, aResult);
+  it.forget(aResult);
+  return NS_OK;
 }
 
 nsXBLContentSink::nsXBLContentSink()
   : mState(eXBL_InDocument),
     mSecondaryState(eXBL_None),
     mDocInfo(nullptr),
     mIsChromeOrResource(false),
     mFoundFirstBinding(false),
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -81,23 +81,23 @@ NS_NewXMLContentSink(nsIXMLContentSink**
                      nsIURI* aURI,
                      nsISupports* aContainer,
                      nsIChannel* aChannel)
 {
   NS_PRECONDITION(nullptr != aResult, "null ptr");
   if (nullptr == aResult) {
     return NS_ERROR_NULL_POINTER;
   }
-  nsXMLContentSink* it = new nsXMLContentSink();
+  nsRefPtr<nsXMLContentSink> it = new nsXMLContentSink();
   
-  nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
   nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
   NS_ENSURE_SUCCESS(rv, rv);
-  
-  return CallQueryInterface(it, aResult);
+
+  it.forget(aResult);
+  return NS_OK;
 }
 
 nsXMLContentSink::nsXMLContentSink()
   : mConstrainSize(true),
     mPrettyPrintXML(true)
 {
 }
 
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -167,17 +167,17 @@ nsXULCommandDispatcher::GetFocusedWindow
   nsresult rv = window->GetDocument(getter_AddRefs(domdoc));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Note: If there is no document, then this window has been cleared and
   // there's nothing left to protect, so let the window pass through.
   if (domdoc && !nsContentUtils::CanCallerAccess(domdoc))
     return NS_ERROR_DOM_SECURITY_ERR;
 
-  CallQueryInterface(window, aWindow);
+  window.forget(aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
--- a/dom/xul/templates/nsXULTemplateQueryProcessorRDF.cpp
+++ b/dom/xul/templates/nsXULTemplateQueryProcessorRDF.cpp
@@ -1309,24 +1309,24 @@ nsXULTemplateQueryProcessorRDF::ParseLit
         nsCOMPtr<nsIRDFInt> intLiteral;
         nsresult errorCode;
         int32_t intValue = aValue.ToInteger(&errorCode);
         if (NS_FAILED(errorCode))
             return NS_ERROR_FAILURE;
         rv = gRDFService->GetIntLiteral(intValue, getter_AddRefs(intLiteral));
         if (NS_FAILED(rv)) 
             return rv;
-        rv = CallQueryInterface(intLiteral, aResult);
+        intLiteral.forget(aResult);
     }
     else {
         nsCOMPtr<nsIRDFLiteral> literal;
         rv = gRDFService->GetLiteral(aValue.get(), getter_AddRefs(literal));
         if (NS_FAILED(rv)) 
             return rv;
-        rv = CallQueryInterface(literal, aResult);
+        literal.forget(aResult);
     }
     return rv;
 }
 
 nsresult
 nsXULTemplateQueryProcessorRDF::CompileTripleCondition(nsRDFQuery* aQuery,
                                                        nsIContent* aCondition,
                                                        TestNode* aParentNode,
--- a/image/src/imgTools.cpp
+++ b/image/src/imgTools.cpp
@@ -136,17 +136,18 @@ static nsresult EncodeImageData(DataSour
                                       size.width,
                                       size.height,
                                       map.mStride,
                                       imgIEncoder::INPUT_FORMAT_HOSTARGB,
                                       aOutputOptions);
   aDataSurface->Unmap();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return CallQueryInterface(encoder, aStream);
+  encoder.forget(aStream);
+  return NS_OK;
 }
 
 NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer,
                                     const nsACString& aMimeType,
                                     const nsAString& aOutputOptions,
                                     nsIInputStream **aStream)
 {
   // Use frame 0 from the image container.
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -499,29 +499,31 @@ NS_IMETHODIMP
 nsJARURI::Clone(nsIURI **result)
 {
     nsresult rv;
 
     nsCOMPtr<nsIJARURI> uri;
     rv = CloneWithJARFileInternal(mJARFile, eHonorRef, getter_AddRefs(uri));
     if (NS_FAILED(rv)) return rv;
 
-    return CallQueryInterface(uri, result);
+    uri.forget(result);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARURI::CloneIgnoringRef(nsIURI **result)
 {
     nsresult rv;
 
     nsCOMPtr<nsIJARURI> uri;
     rv = CloneWithJARFileInternal(mJARFile, eIgnoreRef, getter_AddRefs(uri));
     if (NS_FAILED(rv)) return rv;
 
-    return CallQueryInterface(uri, result);
+    uri.forget(result);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARURI::Resolve(const nsACString &relativePath, nsACString &result)
 {
     nsresult rv;
 
     nsCOMPtr<nsIIOService> ioServ(do_GetIOService(&rv));
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -744,21 +744,19 @@ Preferences::GetPreferences(InfallibleTA
 
 NS_IMETHODIMP
 Preferences::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
   nsresult rv;
 
   if ((nullptr != aPrefRoot) && (*aPrefRoot != '\0')) {
     // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
-    nsPrefBranch* prefBranch = new nsPrefBranch(aPrefRoot, false);
-    if (!prefBranch)
-      return NS_ERROR_OUT_OF_MEMORY;
-
-    rv = CallQueryInterface(prefBranch, _retval);
+    nsRefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, false);
+    prefBranch.forget(_retval);
+    rv = NS_OK;
   } else {
     // special case caching the default root
     nsCOMPtr<nsIPrefBranch> root(sRootBranch);
     root.forget(_retval);
     rv = NS_OK;
   }
   return rv;
 }
--- a/netwerk/protocol/device/AndroidCaptureProvider.cpp
+++ b/netwerk/protocol/device/AndroidCaptureProvider.cpp
@@ -284,17 +284,18 @@ nsresult AndroidCaptureProvider::Init(ns
       if (NS_FAILED(rv))
         return rv;
     }
     else
       return NS_ERROR_OUT_OF_MEMORY;
   } else {
     NS_NOTREACHED("Should not have asked Android for this type!");
   }
-  return CallQueryInterface(stream, aStream);
+  stream.forget(aStream);
+  return NS_OK;
 }
 
 already_AddRefed<AndroidCaptureProvider> GetAndroidCaptureProvider() {
   if (!AndroidCaptureProvider::sInstance) {
     AndroidCaptureProvider::sInstance = new AndroidCaptureProvider();
   }
   nsRefPtr<AndroidCaptureProvider> ret = AndroidCaptureProvider::sInstance;
   return ret.forget();
--- a/netwerk/protocol/device/nsDeviceProtocolHandler.cpp
+++ b/netwerk/protocol/device/nsDeviceProtocolHandler.cpp
@@ -45,33 +45,35 @@ nsDeviceProtocolHandler::NewURI(const ns
                                 nsIURI *baseURI,
                                 nsIURI **result)
 {
   nsRefPtr<nsSimpleURI> uri = new nsSimpleURI();
 
   nsresult rv = uri->SetSpec(spec);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return CallQueryInterface(uri, result);
+  uri.forget(result);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDeviceProtocolHandler::NewChannel2(nsIURI* aURI,
                                      nsILoadInfo* aLoadInfo,
                                      nsIChannel** aResult)
 {
   nsRefPtr<nsDeviceChannel> channel = new nsDeviceChannel();
   nsresult rv = channel->Init(aURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // set the loadInfo on the new channel
   rv = channel->SetLoadInfo(aLoadInfo);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return CallQueryInterface(channel, aResult);
+  channel.forget(aResult);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDeviceProtocolHandler::NewChannel(nsIURI* aURI, nsIChannel **aResult)
 {
   return NewChannel2(aURI, nullptr, aResult);
 }
 
--- a/netwerk/protocol/res/nsResProtocolHandler.cpp
+++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
@@ -232,20 +232,19 @@ nsResProtocolHandler::GetProtocolFlags(u
 NS_IMETHODIMP
 nsResProtocolHandler::NewURI(const nsACString &aSpec,
                              const char *aCharset,
                              nsIURI *aBaseURI,
                              nsIURI **result)
 {
     nsresult rv;
 
-    nsResURL *resURL = new nsResURL();
+    nsRefPtr<nsResURL> resURL = new nsResURL();
     if (!resURL)
         return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(resURL);
 
     // unescape any %2f and %2e to make sure nsStandardURL coalesces them.
     // Later net_GetFileFromURLSpec() will do a full unescape and we want to
     // treat them the same way the file system will. (bugs 380994, 394075)
     nsAutoCString spec;
     const char *src = aSpec.BeginReading();
     const char *end = aSpec.EndReading();
     const char *last = src;
@@ -267,19 +266,19 @@ nsResProtocolHandler::NewURI(const nsACS
              last = src+1; // src will be incremented by the loop
            }
         }
     }
     if (last < src)
       spec.Append(last, src-last);
 
     rv = resURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI);
-    if (NS_SUCCEEDED(rv))
-        rv = CallQueryInterface(resURL, result);
-    NS_RELEASE(resURL);
+    if (NS_SUCCEEDED(rv)) {
+        resURL.forget(result);
+    }
     return rv;
 }
 
 NS_IMETHODIMP
 nsResProtocolHandler::NewChannel2(nsIURI* uri,
                                   nsILoadInfo* aLoadInfo,
                                   nsIChannel** result)
 {
--- a/security/manager/ssl/src/nsProtectedAuthThread.cpp
+++ b/security/manager/ssl/src/nsProtectedAuthThread.cpp
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "pk11func.h"
 #include "mozilla/DebugOnly.h"
-#include "mozilla/RefPtr.h"
+#include "nsRefPtr.h"
 #include "nsCOMPtr.h"
 #include "PSMRunnable.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsPKCS11Slot.h"
 #include "nsProtectedAuthThread.h"
 
 using namespace mozilla;
@@ -79,23 +79,24 @@ NS_IMETHODIMP nsProtectedAuthThread::Get
     // Get token name
     CopyUTF8toUTF16(nsDependentCString(PK11_GetTokenName(mSlot)), _retval);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval)
 {
-    RefPtr<nsPKCS11Slot> slot;
+    nsRefPtr<nsPKCS11Slot> slot;
     {
         MutexAutoLock lock(mMutex);
         slot = new nsPKCS11Slot(mSlot);
     }
 
-    return CallQueryInterface (slot.get(), _retval);
+    slot.forget(_retval);
+    return NS_OK;
 }
 
 void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot)
 {
     MutexAutoLock lock(mMutex);
 
     mSlot = (aSlot) ? PK11_ReferenceSlot(aSlot) : 0;
 }
--- a/xpfe/appshell/nsWindowMediator.cpp
+++ b/xpfe/appshell/nsWindowMediator.cpp
@@ -216,45 +216,43 @@ NS_IMETHODIMP
 nsWindowMediator::GetZOrderDOMWindowEnumerator(
             const char16_t *aWindowType, bool aFrontToBack,
             nsISimpleEnumerator **_retval)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   NS_ENSURE_ARG_POINTER(_retval);
   NS_ENSURE_STATE(mReady);
 
-  nsAppShellWindowEnumerator *enumerator;
+  nsRefPtr<nsAppShellWindowEnumerator> enumerator;
   if (aFrontToBack)
     enumerator = new nsASDOMWindowFrontToBackEnumerator(aWindowType, *this);
   else
     enumerator = new nsASDOMWindowBackToFrontEnumerator(aWindowType, *this);
-  if (enumerator)
-    return CallQueryInterface(enumerator, _retval);
 
-  return NS_ERROR_OUT_OF_MEMORY;
+  enumerator.forget(_retval);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowMediator::GetZOrderXULWindowEnumerator(
             const char16_t *aWindowType, bool aFrontToBack,
             nsISimpleEnumerator **_retval)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   NS_ENSURE_ARG_POINTER(_retval);
   NS_ENSURE_STATE(mReady);
 
-  nsAppShellWindowEnumerator *enumerator;
+  nsRefPtr<nsAppShellWindowEnumerator> enumerator;
   if (aFrontToBack)
     enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this);
   else
     enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this);
-  if (enumerator)
-    return CallQueryInterface(enumerator, _retval);
 
-  return NS_ERROR_OUT_OF_MEMORY;
+  enumerator.forget(_retval);
+  return NS_OK;
 }
 
 int32_t
 nsWindowMediator::AddEnumerator(nsAppShellWindowEnumerator * inEnumerator)
 {
   return mEnumeratorList.AppendElement(inEnumerator) != nullptr;
 }
 
--- a/xpfe/components/windowds/nsWindowDataSource.cpp
+++ b/xpfe/components/windowds/nsWindowDataSource.cpp
@@ -360,17 +360,18 @@ NS_IMETHODIMP nsWindowDataSource::GetTar
         // only allow the range of 1 to 9 for single key access
         if (theIndex < 1 || theIndex > 9) return(NS_RDF_NO_VALUE);
 
         nsCOMPtr<nsIRDFInt> indexInt;
         rv = gRDFService->GetIntLiteral(theIndex, getter_AddRefs(indexInt));
         if (NS_FAILED(rv)) return(rv);
         if (!indexInt) return(NS_ERROR_FAILURE);
 
-        return CallQueryInterface(indexInt, _retval);
+        indexInt.forget(_retval);
+        return NS_OK;
     }
 
     return mInner->GetTarget(aSource, aProperty, aTruthValue, _retval);
 }
 
 /* nsIRDFResource GetSource (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
 NS_IMETHODIMP nsWindowDataSource::GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, bool aTruthValue, nsIRDFResource **_retval)
 {