Bug 1186750 part 4 - Clear runnable list in DeviceStorageRequestParent when being destroyed. r=dhylands
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 19 Nov 2015 16:10:42 +1100
changeset 273248 fa9922692623cea44fb2fb29064e24380372aafb
parent 273247 5add786777f33f60445a5658ba9e3459e7eec84a
child 273249 95069f2ce6487177d7d639ba60677a3049b1094d
push id29696
push usercbook@mozilla.com
push dateThu, 19 Nov 2015 13:45:03 +0000
treeherdermozilla-central@a523d4c7efe2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1186750
milestone45.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 1186750 part 4 - Clear runnable list in DeviceStorageRequestParent when being destroyed. r=dhylands
dom/devicestorage/DeviceStorageRequestParent.cpp
--- a/dom/devicestorage/DeviceStorageRequestParent.cpp
+++ b/dom/devicestorage/DeviceStorageRequestParent.cpp
@@ -388,20 +388,25 @@ DeviceStorageRequestParent::~DeviceStora
 NS_IMPL_ADDREF(DeviceStorageRequestParent)
 NS_IMPL_RELEASE(DeviceStorageRequestParent)
 
 void
 DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
 {
   MutexAutoLock lock(mMutex);
   mActorDestroyed = true;
-  int32_t count = mRunnables.Length();
-  for (int32_t index = 0; index < count; index++) {
-    mRunnables[index]->Cancel();
+  for (auto& runnable : mRunnables) {
+    runnable->Cancel();
   }
+  // Ensure we clear all references to the runnables so that there won't
+  // be leak due to cyclic reference. Note that it is safe to release
+  // the references here, since if a runnable is not cancelled yet, the
+  // corresponding thread should still hold a reference to it, and thus
+  // the runnable will end up being released in that thread, not here.
+  mRunnables.Clear();
 }
 
 DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(
   DeviceStorageRequestParent* aParent,
   uint64_t aFreeSpace)
   : CancelableRunnable(aParent)
   , mFreeSpace(aFreeSpace)
 {