Bug 1512557 - Convert nsIStringBundle pointers to nsCOMPtrs and release them when shutting down. r=jorgk DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 07 Dec 2018 14:58:20 +1300
changeset 33864 21219ad63ec84a637511fb8b76ddf34a874d51ca
parent 33863 e0c27feaf097359da1f9e8796800c2ca7da2d637
child 33865 463d4f409e9a2d0e67befd639afce76dc3cef5e0
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersjorgk
bugs1512557
Bug 1512557 - Convert nsIStringBundle pointers to nsCOMPtrs and release them when shutting down. r=jorgk DONTBUILD
mailnews/intl/nsCharsetConverterManager.cpp
mailnews/intl/nsCharsetConverterManager.h
--- a/mailnews/intl/nsCharsetConverterManager.cpp
+++ b/mailnews/intl/nsCharsetConverterManager.cpp
@@ -14,36 +14,31 @@
 
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "../base/util/nsMsgI18N.h"
 
 // just for CONTRACTIDs
 #include "nsCharsetConverterManager.h"
 
-static nsIStringBundle * sDataBundle;
-static nsIStringBundle * sTitleBundle;
+static nsCOMPtr<nsIStringBundle> sDataBundle;
+static nsCOMPtr<nsIStringBundle> sTitleBundle;
 
 // Class nsCharsetConverterManager [implementation]
 
 NS_IMPL_ISUPPORTS(nsCharsetConverterManager, nsICharsetConverterManager)
 
 nsCharsetConverterManager::nsCharsetConverterManager()
 {
 }
 
 nsCharsetConverterManager::~nsCharsetConverterManager()
 {
-}
-
-//static
-void nsCharsetConverterManager::Shutdown()
-{
-  NS_IF_RELEASE(sDataBundle);
-  NS_IF_RELEASE(sTitleBundle);
+  sDataBundle = nullptr;
+  sTitleBundle = nullptr;
 }
 
 static
 nsresult LoadBundle(const char* aBundleURLSpec, nsIStringBundle ** aResult)
 {
   nsCOMPtr<nsIStringBundleService> sbServ =
     mozilla::services::GetStringBundleService();
   if (!sbServ)
@@ -88,17 +83,18 @@ nsresult GetBundleValue(nsIStringBundle 
 static
 nsresult GetCharsetDataImpl(const char * aCharset, const char16_t * aProp,
                             nsAString& aResult)
 {
   NS_ENSURE_ARG_POINTER(aCharset);
   // aProp can be nullptr
 
   if (!sDataBundle) {
-    nsresult rv = LoadBundle("resource://gre-resources/charsetData.properties", &sDataBundle);
+    nsresult rv = LoadBundle("resource://gre-resources/charsetData.properties",
+                             getter_AddRefs(sDataBundle));
     if (NS_FAILED(rv))
       return rv;
   }
 
   return GetBundleValue(sDataBundle, aCharset, nsDependentString(aProp), aResult);
 }
 
 //static
@@ -140,17 +136,18 @@ nsCharsetConverterManager::GetCharsetAli
 
 NS_IMETHODIMP
 nsCharsetConverterManager::GetCharsetTitle(const char * aCharset,
                                            nsAString& aResult)
 {
   NS_ENSURE_ARG_POINTER(aCharset);
 
   if (!sTitleBundle) {
-    nsresult rv = LoadBundle("chrome://messenger/locale/charsetTitles.properties", &sTitleBundle);
+    nsresult rv = LoadBundle("chrome://messenger/locale/charsetTitles.properties",
+                             getter_AddRefs(sTitleBundle));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return GetBundleValue(sTitleBundle, aCharset, NS_LITERAL_STRING(".title"), aResult);
 }
 
 NS_IMETHODIMP
 nsCharsetConverterManager::GetCharsetData(const char * aCharset,
--- a/mailnews/intl/nsCharsetConverterManager.h
+++ b/mailnews/intl/nsCharsetConverterManager.h
@@ -14,18 +14,16 @@ class nsCharsetConverterManager : public
   friend class nsCharsetAlias;
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSICHARSETCONVERTERMANAGER
 
 public:
   nsCharsetConverterManager();
 
-  static void Shutdown();
-
 private:
   virtual ~nsCharsetConverterManager();
 
   static bool IsInternal(const nsACString& aCharset);
 };
 
 #endif // nsCharsetConverterManager_h__