summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-07-05 09:58:09 -0600
committerAndreas Kling <kling@serenityos.org>2021-07-05 18:11:58 +0200
commitb2e6088bff209e8bbb838cc86233e7d3f24ed650 (patch)
tree4a7a36c94993c8205b4bceb6ca08e5fa9d21c9d5
parent8aafbd917afd45cfd9648a85bf70ba1d7a63d0da (diff)
downloadserenity-b2e6088bff209e8bbb838cc86233e7d3f24ed650.zip
LibThreading: Fix BackgroundAction result use-after-free
We need to move the result out of the BackgroundAction object before posting the completion callback as there is a chance the BackgroundAction instance gets freed before the event loop runs our callback. Fixes #7641
-rw-r--r--Userland/Libraries/LibThreading/BackgroundAction.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibThreading/BackgroundAction.h b/Userland/Libraries/LibThreading/BackgroundAction.h
index d169ae4aa3..18b346b154 100644
--- a/Userland/Libraries/LibThreading/BackgroundAction.h
+++ b/Userland/Libraries/LibThreading/BackgroundAction.h
@@ -66,8 +66,8 @@ private:
enqueue_work([this] {
m_result = m_action(*this);
if (m_on_complete) {
- Core::EventLoop::current().post_event(*this, make<Core::DeferredInvocationEvent>([this](auto&) {
- m_on_complete(m_result.release_value());
+ Core::EventLoop::current().post_event(*this, make<Core::DeferredInvocationEvent>([this, result = m_result.release_value()](auto&) {
+ m_on_complete(result);
this->remove_from_parent();
}));
Core::EventLoop::wake();