[QUEUED scylla next] sstable_directory: parallel_for_each_restricted: keep func alive across calls

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
May 24, 2022, 11:02:09 AM5/24/22
to scylladb-dev@googlegroups.com, Benny Halevy
From: Benny Halevy <bha...@scylladb.com>
Committer: Benny Halevy <bha...@scylladb.com>
Branch: next

sstable_directory: parallel_for_each_restricted: keep func alive across calls

Without that there's use-after-free when called from
distributed_loader::make_sstables_available where
func is turned into a coroutine and the shared_sstable parameter
is not explicitly copied and captured for the continuation
of sst->move_to_new_dir.

Signed-off-by: Benny Halevy <bha...@scylladb.com>

---
diff --git a/sstables/sstable_directory.cc b/sstables/sstable_directory.cc
--- a/sstables/sstable_directory.cc
+++ b/sstables/sstable_directory.cc
@@ -430,9 +430,9 @@ sstable_directory::do_for_each_sstable(std::function<future<>(sstables::shared_s
template <typename Container, typename Func>
future<>
sstable_directory::parallel_for_each_restricted(Container&& C, Func&& func) {
- return do_with(std::move(C), [this, func = std::move(func)] (Container& c) mutable {
- return max_concurrent_for_each(c, _load_parallelism, [this, func = std::move(func)] (auto& el) mutable {
- return with_semaphore(_load_semaphore, 1, [this, func, el = std::move(el)] () mutable {
+ return do_with(std::move(C), std::move(func), [this] (Container& c, Func& func) mutable {
+ return max_concurrent_for_each(c, _load_parallelism, [this, &func] (auto& el) mutable {
+ return with_semaphore(_load_semaphore, 1, [this, &func, el = std::move(el)] () mutable {
return func(el);
});
});

Commit Bot

<bot@cloudius-systems.com>
unread,
May 25, 2022, 12:07:36 AM5/25/22
to scylladb-dev@googlegroups.com, Benny Halevy
From: Benny Halevy <bha...@scylladb.com>
Committer: Benny Halevy <bha...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages