Bug 1261231: Fix shutdown leak in imgLoader::GetInstance. r=gabor
authorKris Maglione <maglione.k@gmail.com>
Thu, 31 Mar 2016 16:26:38 -0700
changeset 331633 9774863180f92d75e7851f138bed71fe9828122a
parent 331632 e2f5cd553b44f73fa85c8427aed560f9a47f0ce9
child 331634 0ae340c9ece2fcff77aaf6910d42865677577b1c
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1261231
milestone48.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 1261231: Fix shutdown leak in imgLoader::GetInstance. r=gabor MozReview-Commit-ID: K3kQrva1mG7
image/imgLoader.cpp
image/imgLoader.h
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1131,26 +1131,26 @@ NS_IMPL_ISUPPORTS(imgLoader, imgILoader,
 
 static imgLoader* gSingleton = nullptr;
 static imgLoader* gPBSingleton = nullptr;
 
 imgLoader*
 imgLoader::Singleton()
 {
   if (!gSingleton) {
-    gSingleton = imgLoader::Create();
+    gSingleton = imgLoader::Create().take();
   }
   return gSingleton;
 }
 
 imgLoader*
 imgLoader::PBSingleton()
 {
   if (!gPBSingleton) {
-    gPBSingleton = imgLoader::Create();
+    gPBSingleton = imgLoader::Create().take();
     gPBSingleton->RespectPrivacyNotifications();
   }
   return gPBSingleton;
 }
 
 imgLoader::imgLoader()
 : mUncachedImagesMutex("imgLoader::UncachedImages"), mRespectPrivacy(false)
 {
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -248,28 +248,28 @@ public:
 
   static imgLoader* Singleton();
   static imgLoader* PBSingleton();
 
   imgLoader();
 
   nsresult Init();
 
-  static imgLoader* Create()
+  static already_AddRefed<imgLoader>
+  Create()
   {
       // Unfortunately, we rely on XPCOM module init happening
       // before imgLoader creation. For now, it's easier
       // to just call CallCreateInstance() which will init
       // the image module instead of calling new imgLoader
       // directly.
-      imgILoader* loader;
-      CallCreateInstance("@mozilla.org/image/loader;1", &loader);
+      nsCOMPtr<imgILoader> loader = do_CreateInstance("@mozilla.org/image/loader;1");
       // There's only one imgLoader implementation so we
       // can safely cast to it.
-      return static_cast<imgLoader*>(loader);
+      return loader.forget().downcast<imgLoader>();
   }
 
   static already_AddRefed<imgLoader>
   GetInstance();
 
   nsresult LoadImage(nsIURI* aURI,
                      nsIURI* aInitialDocumentURI,
                      nsIURI* aReferrerURI,