From a610d9a3d1c2dd14d7a93f12a320174d86653387 Mon Sep 17 00:00:00 2001 From: Rummskartoffel Date: Sat, 15 Jan 2022 15:34:59 +0100 Subject: [PATCH] Assistant: Fix crash in FileProvider background thread upon exit If the Threading::BackgroundAction for filesystem indexing in FileProvider hadn't finished by the time the main thread exited, it would still try to access the FileProvider object that lived in the main thread, thereby causing a segfault and crashing. This commit prevents FileProvider from being destroyed while the background thread is still running by giving the background thread a strong reference to its FileProvider. --- Userland/Applications/Assistant/Providers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Applications/Assistant/Providers.cpp b/Userland/Applications/Assistant/Providers.cpp index 190b1fe5de..f2a8c590ea 100644 --- a/Userland/Applications/Assistant/Providers.cpp +++ b/Userland/Applications/Assistant/Providers.cpp @@ -164,7 +164,7 @@ void FileProvider::build_filesystem_cache() m_work_queue.enqueue("/"); (void)Threading::BackgroundAction::construct( - [this](auto&) { + [this, strong_ref = NonnullRefPtr(*this)](auto&) { String slash = "/"; auto timer = Core::ElapsedTimer::start_new(); while (!m_work_queue.is_empty()) {