Skip to content

Commit

Permalink
LibThread: Fix destroying background actions
Browse files Browse the repository at this point in the history
In the old model, before bc319d9, the parent
(the background thread) would delete us when it exits (i.e. never), so we had to
keep track of our own refcount in order to destroy ourselves when we're done.

With bc319d9, the parent keeps additional
reference to us, so:
* There should be no need to explicitly ref() ourselves
* The unref() would not get rid of the last reference to us anymore

The latter is why all the BackgroundAction's were getting leaked. Fix this by
simply unparenting ourselves from the background thread when we're done.
  • Loading branch information
bugaevc authored and awesomekling committed Feb 25, 2020
1 parent ab9a078 commit cbf2881
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Libraries/LibThread/BackgroundAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ class BackgroundAction final : public Core::Object
{
LOCKER(all_actions().lock());

this->ref();
all_actions().resource().enqueue([this] {
m_result = m_action();
if (m_on_complete) {
Core::EventLoop::current().post_event(*this, make<Core::DeferredInvocationEvent>([this](auto&) {
m_on_complete(m_result.release_value());
this->unref();
this->remove_from_parent();
}));
Core::EventLoop::wake();
} else
this->unref();
} else {
this->remove_from_parent();
}
});
}

Expand Down

0 comments on commit cbf2881

Please sign in to comment.