Commit cf5b2228 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix potential use after move in window

Summary:
The lambda that gets the ctx moved in can be created before the via call.

(Note: this ignores all push blocking failures!)

Reviewed By: spalamarchuk

Differential Revision: D13009656

fbshipit-source-id: 1c89905e544adc829124277465c32958a3489845
parent 07f3b3df
...@@ -1826,13 +1826,15 @@ window(Executor::KeepAlive<> executor, Collection input, F func, size_t n) { ...@@ -1826,13 +1826,15 @@ window(Executor::KeepAlive<> executor, Collection input, F func, size_t n) {
static void spawn(std::shared_ptr<WindowContext> ctx) { static void spawn(std::shared_ptr<WindowContext> ctx) {
size_t i = ctx->i.fetch_add(1, std::memory_order_relaxed); size_t i = ctx->i.fetch_add(1, std::memory_order_relaxed);
if (i < ctx->input.size()) { if (i < ctx->input.size()) {
makeSemiFutureWith([&] { return ctx->func(std::move(ctx->input[i])); }) auto fut = makeSemiFutureWith(
.via(ctx->executor.get()) [&] { return ctx->func(std::move(ctx->input[i])); })
.setCallback_([ctx = std::move(ctx), i](Try<Result>&& t) mutable { .via(ctx->executor.get());
ctx->promises[i].setTry(std::move(t));
// Chain another future onto this one fut.setCallback_([ctx = std::move(ctx), i](Try<Result>&& t) mutable {
spawn(std::move(ctx)); ctx->promises[i].setTry(std::move(t));
}); // Chain another future onto this one
spawn(std::move(ctx));
});
} }
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment