Commit 582c04fe authored by Dimitrios Katsaros's avatar Dimitrios Katsaros

async: Changed lambda capture to respect object lifetime

The lambda was capturing the entire object being passed, rather then
only the needed resource. On edge cases where the captured object
would fall out of scope (deallocated) before the promise completion,
it would try to use deallocated members, which would cause a segmentation
fault.
parent 79e1a118
...@@ -570,15 +570,18 @@ namespace Async { ...@@ -570,15 +570,18 @@ namespace Async {
template<typename P> template<typename P>
void finishResolve(P& promise) { void finishResolve(P& promise) {
auto chainer = makeChainer(promise); auto chainer = makeChainer(promise);
promise.then(std::move(chainer), [=](std::exception_ptr exc) { std::weak_ptr<Core> weakPtr = this->chain_;
auto core = this->chain_; promise.then(std::move(chainer), [weakPtr](std::exception_ptr exc) {
core->exc = std::move(exc); if (auto core = weakPtr.lock()) {
core->state = State::Rejected; core->exc = std::move(exc);
core->state = State::Rejected;
for (const auto& req: core->requests) {
req->reject(core); for (const auto& req: core->requests) {
req->reject(core);
}
} }
}); });
} }
Resolve resolve_; Resolve resolve_;
......
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