Bug 1261231: Fix shutdown leak in imgLoader::GetInstance. r?seth draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 31 Mar 2016 16:26:38 -0700
changeset 346362 5d64f904b99b8c17c391d8940ee18dfc905509c5
parent 346302 bccb11375f2af838cda714d42fd8cef78f5c7bf1
child 517434 3f246a956223699cd6c59a35bf4fb721e7494b30
push id14361
push usermaglione.k@gmail.com
push dateThu, 31 Mar 2016 23:38:37 +0000
reviewersseth
bugs1261231
milestone48.0a1
Bug 1261231: Fix shutdown leak in imgLoader::GetInstance. r?seth MozReview-Commit-ID: K3kQrva1mG7
image/imgLoader.cpp
image/imgLoader.h
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1110,26 +1110,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,