Browse Source

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.
Rummskartoffel 3 years ago
parent
commit
a610d9a3d1
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Userland/Applications/Assistant/Providers.cpp

+ 1 - 1
Userland/Applications/Assistant/Providers.cpp

@@ -164,7 +164,7 @@ void FileProvider::build_filesystem_cache()
     m_work_queue.enqueue("/");
     m_work_queue.enqueue("/");
 
 
     (void)Threading::BackgroundAction<int>::construct(
     (void)Threading::BackgroundAction<int>::construct(
-        [this](auto&) {
+        [this, strong_ref = NonnullRefPtr(*this)](auto&) {
             String slash = "/";
             String slash = "/";
             auto timer = Core::ElapsedTimer::start_new();
             auto timer = Core::ElapsedTimer::start_new();
             while (!m_work_queue.is_empty()) {
             while (!m_work_queue.is_empty()) {