Skip to content

Commit

Permalink
Fix heap-after-use bug in 'Concurrent' (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
benh authored Aug 24, 2022
1 parent da1f5ec commit a4a3d01
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions eventuals/concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,26 @@ struct _Concurrent final {
|| !fibers_done_;
};
}))
>> Then([callback = std::move(callback)]() mutable {
callback();
})
>> Terminal();
>> Terminal()
.start([callback = std::move(callback)]() mutable {
// NOTE: we need to move 'callback' on the stack
// and invoke it in a 'Terminal' so that in the
// event invoking it will cause this eventual that
// we're currently executing to get cleaned up we
// won't have a possible heap-after-use issue.
Callback<void()> callback_on_stack = std::move(callback);
callback_on_stack();
})
.fail([](auto&& unreachable) {
static_assert(
always_false_v<decltype(unreachable)>,
"Unreachable");
})
.stop([](auto&& unreachable) {
static_assert(
always_false_v<decltype(unreachable)>,
"Unreachable");
});
}

// Returns an eventual which handles when "downstream" requests
Expand Down

0 comments on commit a4a3d01

Please sign in to comment.