Avoid service worker thread crash 63/318063/2 accepted/tizen/unified/20240925.061429 accepted/tizen/unified/toolchain/20241004.101738 accepted/tizen/unified/x/20240925.064713 accepted/tizen/unified/x/asan/20241014.000107 submit/tizen/20240924.160013
authorchenhuasheng <hsheng.chen@samsung.com>
Tue, 24 Sep 2024 06:41:02 +0000 (14:41 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 24 Sep 2024 09:23:50 +0000 (09:23 +0000)
Before using GetContentClient(), it's nececssary
to check whether it is valid

Change-Id: I6813c399e2b8fc2869f1a93f6cc35af229e90492
Signed-off-by: chenhuasheng <hsheng.chen@samsung.com>
content/renderer/service_worker/service_worker_context_client.cc

index 1a0ee0160e0a61fe5608cb1ccef56e0da3139241..a28648f529f6c35c8e9e8ae3c5d8f073bc9cf3d4 100644 (file)
@@ -380,8 +380,13 @@ void ServiceWorkerContextClient::WillDestroyWorkerContext(
   // same thread.
   context_.reset();
 
-  GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread(
-      context, service_worker_version_id_, service_worker_scope_, script_url_);
+  if (GetContentClient() && GetContentClient()->renderer()) {
+    GetContentClient()
+        ->renderer()
+        ->WillDestroyServiceWorkerContextOnWorkerThread(
+            context, service_worker_version_id_, service_worker_scope_,
+            script_url_);
+  }
 }
 
 void ServiceWorkerContextClient::WorkerContextDestroyed() {
@@ -510,7 +515,8 @@ void ServiceWorkerContextClient::SendWorkerStarted(
   // |context_| is valid because this task was posted to |worker_task_runner_|.
   DCHECK(context_);
 
-  if (GetContentClient()->renderer()) {  // nullptr in unit_tests.
+  if (GetContentClient() &&
+      GetContentClient()->renderer()) {  // nullptr in unit_tests.
     GetContentClient()->renderer()->DidStartServiceWorkerContextOnWorkerThread(
         service_worker_version_id_, service_worker_scope_, script_url_);
   }