Bug 822398: Use PL_DHASH_REMOVE to remove an entry we're enumerating. r=kanru
authorChris Jones <jones.chris.g@gmail.com>
Thu, 27 Dec 2012 02:43:55 -0800
changeset 117096 de53cfa4b4917d15d37d42b3caec6daf41d00899
parent 117095 bda50f10f69d15487772c0dfd48a31d741d4a4d6
child 117097 c151510f79fbc6ed1a1ed0e4b7f1dda78f6ef4ea
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskanru
bugs822398
milestone20.0a1
Bug 822398: Use PL_DHASH_REMOVE to remove an entry we're enumerating. r=kanru
hal/HalWakeLock.cpp
--- a/hal/HalWakeLock.cpp
+++ b/hal/HalWakeLock.cpp
@@ -61,38 +61,40 @@ CountWakeLocks(const uint64_t& aKey, Loc
   LockCount* totalCount = static_cast<LockCount*>(aUserArg);
   totalCount->numLocks += aCount.numLocks;
   totalCount->numHidden += aCount.numHidden;
 
   return PL_DHASH_NEXT;
 }
 
 static PLDHashOperator
-RemoveChildFromList(const nsAString& aKey, ProcessLockTable* aTable, void* aUserArg)
+RemoveChildFromList(const nsAString& aKey, nsAutoPtr<ProcessLockTable>& aTable,
+                    void* aUserArg)
 {
   MOZ_ASSERT(aUserArg);
 
+  PLDHashOperator op = PL_DHASH_NEXT;
   uint64_t childID = *static_cast<uint64_t*>(aUserArg);
   if (aTable->Get(childID, NULL)) {
     aTable->Remove(childID);
     if (sActiveListeners) {
       LockCount totalCount;
       WakeLockInformation info;
       aTable->EnumerateRead(CountWakeLocks, &totalCount);
       if (!totalCount.numLocks) {
-        sLockTable->Remove(aKey);
+        op = PL_DHASH_REMOVE;
       }
       info.numLocks() = totalCount.numLocks;
       info.numHidden() = totalCount.numHidden;
       info.topic() = aKey;
       NotifyWakeLockChange(info);
     }
   }
 
-  return PL_DHASH_NEXT;
+  return op;
 }
 
 class ClearHashtableOnShutdown MOZ_FINAL : public nsIObserver {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 };
 
@@ -131,17 +133,17 @@ CleanupOnContentShutdown::Observe(nsISup
     NS_WARNING("ipc:content-shutdown message without property bag as subject");
     return NS_OK;
   }
 
   uint64_t childID = 0;
   nsresult rv = props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"),
                                            &childID);
   if (NS_SUCCEEDED(rv)) {
-    sLockTable->EnumerateRead(RemoveChildFromList, &childID);
+    sLockTable->Enumerate(RemoveChildFromList, &childID);
   } else {
     NS_WARNING("ipc:content-shutdown message without childID property");
   }
   return NS_OK;
 }
 
 static void
 Init()