From a513e01b01497178672845ea1ed8f6ce90d4f5c9 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 9 Mar 2022 13:13:45 -0500 Subject: [PATCH] Fix shutdown crash in RenderProcessHostImpl::Cleanup (fixes issue #3276) Execute all pending UI thread tasks at the beginning of the shutdown sequence. --- libcef/browser/main_runner.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libcef/browser/main_runner.cc b/libcef/browser/main_runner.cc index f5fbb19de..d4284ee6c 100644 --- a/libcef/browser/main_runner.cc +++ b/libcef/browser/main_runner.cc @@ -482,6 +482,16 @@ void CefMainRunner::FinishShutdownOnUIThread( base::WaitableEvent* uithread_shutdown_event) { CEF_REQUIRE_UIT(); + // Execute all pending tasks now before proceeding with shutdown. Otherwise, + // objects bound to tasks and released at the end of shutdown via + // BrowserTaskExecutor::Shutdown may attempt to access other objects that have + // already been destroyed (for example, if teardown results in a call to + // RenderProcessHostImpl::Cleanup). + content::BrowserTaskExecutor::RunAllPendingTasksOnThreadForTesting( + content::BrowserThread::UI); + content::BrowserTaskExecutor::RunAllPendingTasksOnThreadForTesting( + content::BrowserThread::IO); + static_cast(main_runner_.get()) ->ShutdownOnUIThread();