浏览代码

LibGUI: Resolve use-after-free error

Objects taken by reference are no longer valid when used in
`deferred_invoke`. Explicitly copying them solve the issue.
Lucas CHOLLET 2 年之前
父节点
当前提交
a9cc61224d
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      Userland/Libraries/LibGUI/FileSystemModel.cpp

+ 1 - 1
Userland/Libraries/LibGUI/FileSystemModel.cpp

@@ -729,7 +729,7 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node)
     auto const on_error = [path, update_progress](Error error) -> void {
         // Note: We need to defer that to avoid the function removing its last reference
         //       i.e. trying to destroy itself, which is prohibited.
-        Core::EventLoop::current().deferred_invoke([&] {
+        Core::EventLoop::current().deferred_invoke([path, error = Error::copy(error)]() mutable {
             s_thumbnail_cache.with_locked([path, error = move(error)](auto& cache) {
                 if (error != Error::from_errno(ECANCELED)) {
                     cache.thumbnail_cache.set(path, nullptr);