Bug 1458970 Avoid accessing mClientSource when a worker is Terminating in more places. r=baku
authorBen Kelly <ben@wanderview.com>
Fri, 04 May 2018 06:35:36 -0700
changeset 473015 86d1e26507dbe15f9b93fb4ba87be152d1f7b0be
parent 473014 f6cb88fc621fdc8be0b9426ef9d35becf5321f70
child 473016 5bc4513eef701a4874bffc984868a15f485a24b4
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1458970
milestone61.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 1458970 Avoid accessing mClientSource when a worker is Terminating in more places. r=baku
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerPrivate.h
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -3521,30 +3521,42 @@ WorkerPrivate::GetClientState() const
   AssertIsOnWorkerThread();
   MOZ_DIAGNOSTIC_ASSERT(mClientSource);
   ClientState state;
   mClientSource->SnapshotState(&state);
   return Move(state);
 }
 
 const Maybe<ServiceWorkerDescriptor>
-WorkerPrivate::GetController() const
+WorkerPrivate::GetController()
 {
   AssertIsOnWorkerThread();
+  {
+    MutexAutoLock lock(mMutex);
+    if (mStatus >= Terminating) {
+      return Maybe<ServiceWorkerDescriptor>();
+    }
+  }
   MOZ_DIAGNOSTIC_ASSERT(mClientSource);
   return mClientSource->GetController();
 }
 
 void
 WorkerPrivate::Control(const ServiceWorkerDescriptor& aServiceWorker)
 {
   AssertIsOnWorkerThread();
-  MOZ_DIAGNOSTIC_ASSERT(mClientSource);
   MOZ_DIAGNOSTIC_ASSERT(!IsChromeWorker());
   MOZ_DIAGNOSTIC_ASSERT(Type() != WorkerTypeService);
+  {
+    MutexAutoLock lock(mMutex);
+    if (mStatus >= Terminating) {
+      return;
+    }
+  }
+  MOZ_DIAGNOSTIC_ASSERT(mClientSource);
   mClientSource->SetController(aServiceWorker);
 }
 
 void
 WorkerPrivate::ExecutionReady()
 {
   AssertIsOnWorkerThread();
   {
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -555,17 +555,17 @@ public:
 
   Maybe<ClientInfo>
   GetClientInfo() const;
 
   const ClientState
   GetClientState() const;
 
   const Maybe<ServiceWorkerDescriptor>
-  GetController() const;
+  GetController();
 
   void
   Control(const ServiceWorkerDescriptor& aServiceWorker);
 
   void
   ExecutionReady();
 
   PerformanceStorage*