From 23d5f04e7bc40aeb453cdad74fbf9f2f52d8fbc6 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 19 Jul 2022 09:56:06 -0700 Subject: [PATCH] Retain a reference to the CFRunLoop until MessageLoopDarwin::Terminate exits (flutter/engine#34735) --- .../src/flutter/fml/platform/darwin/message_loop_darwin.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/fml/platform/darwin/message_loop_darwin.mm b/engine/src/flutter/fml/platform/darwin/message_loop_darwin.mm index 969ff8b4670..d48cf334992 100644 --- a/engine/src/flutter/fml/platform/darwin/message_loop_darwin.mm +++ b/engine/src/flutter/fml/platform/darwin/message_loop_darwin.mm @@ -63,7 +63,12 @@ void MessageLoopDarwin::Run() { void MessageLoopDarwin::Terminate() { running_ = false; - CFRunLoopStop(loop_); + + // Ensure that the CFRunLoop remains alive through the end of this function + // even if the loop's thread exits and drops its reference to the loop. + CFRef local_loop(loop_); + + CFRunLoopStop(local_loop); } void MessageLoopDarwin::WakeUp(fml::TimePoint time_point) {