Bug 605908 - test_parent.js leaks objects. Part 1: nsPermissionManager leak. r=jdm, a=sdwilsh
authorDan Witte <dwitte@mozilla.com>
Thu, 21 Oct 2010 11:36:14 -0700
changeset 56323 e674806e6889520c45a49db2a54597b3f30335b5
parent 56322 8d1aca43c54b59b7bca7e596d019d5f8620991ee
child 56324 0434c3cf627948b5c760fae378dc8ea40efbed5e
push idunknown
push userunknown
push dateunknown
reviewersjdm, sdwilsh
bugs605908
milestone2.0b8pre
Bug 605908 - test_parent.js leaks objects. Part 1: nsPermissionManager leak. r=jdm, a=sdwilsh
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
extensions/cookie/nsPermissionManager.cpp
extensions/cookie/nsPermissionManager.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -445,18 +445,18 @@ ContentChild::RecvGeolocationUpdate(cons
   gs->Update(position);
   return true;
 }
 
 bool
 ContentChild::RecvAddPermission(const IPC::Permission& permission)
 {
 #if MOZ_PERMISSIONS
-  nsPermissionManager *permissionManager =
-    (nsPermissionManager*)nsPermissionManager::GetSingleton();
+  nsRefPtr<nsPermissionManager> permissionManager =
+    nsPermissionManager::GetSingleton();
   NS_ABORT_IF_FALSE(permissionManager, 
                    "We have no permissionManager in the Content process !");
 
   permissionManager->AddInternal(nsCString(permission.host),
                                  nsCString(permission.type),
                                  permission.capability,
                                  0,
                                  permission.expireType,
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -216,18 +216,18 @@ ContentParent::EnsurePrefService()
                      "We lost prefService in the Chrome process !");
     }
 }
 
 bool
 ContentParent::RecvReadPermissions(nsTArray<IPC::Permission>* aPermissions)
 {
 #ifdef MOZ_PERMISSIONS
-    nsPermissionManager *permissionManager =
-        (nsPermissionManager*)nsPermissionManager::GetSingleton();
+    nsRefPtr<nsPermissionManager> permissionManager =
+        nsPermissionManager::GetSingleton();
     NS_ABORT_IF_FALSE(permissionManager,
                  "We have no permissionManager in the Chrome process !");
 
     nsISimpleEnumerator *enumerator;
     nsresult rv = permissionManager->GetEnumerator(&enumerator);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Could not get enumerator!");
     while(1) {
         PRBool hasMore;
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -182,21 +182,21 @@ nsPermissionManager::~nsPermissionManage
 {
   RemoveAllFromMemory();
 }
 
 // static
 nsIPermissionManager*
 nsPermissionManager::GetXPCOMSingleton()
 {
-  return GetSingleton();
+  return GetSingleton().get();
 }
 
 // static
-nsIPermissionManager*
+already_AddRefed<nsPermissionManager>
 nsPermissionManager::GetSingleton()
 {
   if (gPermissionManager) {
     NS_ADDREF(gPermissionManager);
     return gPermissionManager;
   }
 
   // Create a new singleton nsPermissionManager.
--- a/extensions/cookie/nsPermissionManager.h
+++ b/extensions/cookie/nsPermissionManager.h
@@ -163,17 +163,17 @@ public:
   // nsISupports
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPERMISSIONMANAGER
   NS_DECL_NSIOBSERVER
 
   nsPermissionManager();
   virtual ~nsPermissionManager();
   static nsIPermissionManager* GetXPCOMSingleton();
-  static nsIPermissionManager* GetSingleton();
+  static already_AddRefed<nsPermissionManager> GetSingleton();
   nsresult Init();
 
   // enums for AddInternal()
   enum OperationType {
     eOperationNone,
     eOperationAdding,
     eOperationRemoving,
     eOperationChanging