From 4a26a2b46b13f08cfc6d4112ed0aa120d7e619c2 Mon Sep 17 00:00:00 2001 From: Chase Latta Date: Mon, 11 Jan 2021 22:41:58 +0000 Subject: [PATCH] [dart-runner] Avoid calling Destroy on nullptr The runner was calling Destroy() on the microtask after the internal queue had been set to null. this checks to make sure that the queue is not null before trying to access it. This was leading to a crash when bumping to clang-12 causing the roll into fuchsia GI to fail. --- .../fuchsia/dart_runner/dart_component_controller.cc | 6 +++++- shell/platform/fuchsia/dart_runner/dart_runner.cc | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/shell/platform/fuchsia/dart_runner/dart_component_controller.cc b/shell/platform/fuchsia/dart_runner/dart_component_controller.cc index 3680a875d1ec4..dd9b16bd65aee 100644 --- a/shell/platform/fuchsia/dart_runner/dart_component_controller.cc +++ b/shell/platform/fuchsia/dart_runner/dart_component_controller.cc @@ -440,7 +440,11 @@ bool DartComponentController::Main() { void DartComponentController::Kill() { if (Dart_CurrentIsolate()) { - tonic::DartMicrotaskQueue::GetForCurrentThread()->Destroy(); + tonic::DartMicrotaskQueue* queue = + tonic::DartMicrotaskQueue::GetForCurrentThread(); + if (queue) { + queue->Destroy(); + } loop_->Quit(); diff --git a/shell/platform/fuchsia/dart_runner/dart_runner.cc b/shell/platform/fuchsia/dart_runner/dart_runner.cc index 415d2885c60c2..2a87776cb4d51 100644 --- a/shell/platform/fuchsia/dart_runner/dart_runner.cc +++ b/shell/platform/fuchsia/dart_runner/dart_runner.cc @@ -83,7 +83,12 @@ void IsolateShutdownCallback(void* isolate_group_data, void* isolate_data) { auto dispatcher = async_get_default_dispatcher(); auto loop = async_loop_from_dispatcher(dispatcher); if (loop) { - tonic::DartMicrotaskQueue::GetForCurrentThread()->Destroy(); + tonic::DartMicrotaskQueue* queue = + tonic::DartMicrotaskQueue::GetForCurrentThread(); + if (queue) { + queue->Destroy(); + } + async_loop_quit(loop); }