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.
This commit is contained in:
Rummskartoffel 2022-01-15 15:34:59 +01:00 committed by Andreas Kling
parent ada1d4906e
commit a610d9a3d1
Notes: sideshowbarker 2024-07-17 20:49:45 +09:00

View file

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