Skip to content

Commit

Permalink
Fix crash in run_actions when calling quit
Browse files Browse the repository at this point in the history
(cherry picked from commit 6315f28)
  • Loading branch information
Neverlord authored and timwoj committed Jul 26, 2024
1 parent feef0b9 commit 8db2862
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libcaf_core/caf/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class CAF_CORE_EXPORT action {
pimpl_->dispose();
}

void swap(action& other) noexcept {
pimpl_.swap(other.pimpl_);
}

// -- conversion -------------------------------------------------------------

/// Returns a smart pointer to the implementation.
Expand Down
8 changes: 7 additions & 1 deletion libcaf_core/src/scheduled_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,15 @@ void scheduled_actor::deregister_stream(uint64_t stream_id) {

void scheduled_actor::run_actions() {
if (!actions_.empty()) {
// Note: if the first actions is null, it means that we are already running
// actions right now. This can happen if an action calls `quit`, which will
// call `run_actions` again.
if (!actions_.front())
return;
// Note: can't use iterators here since actions may add to the vector.
for (auto index = size_t{0}; index < actions_.size(); ++index) {
auto f = std::move(actions_[index]);
action f;
f.swap(actions_[index]);
f.run();
}
actions_.clear();
Expand Down

0 comments on commit 8db2862

Please sign in to comment.