From 9d0a8497f9693bccdd1c031104ea5837dc62e4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 3 Apr 2015 16:34:05 +0200 Subject: Async: fix crash in Job::nestedJobWrapper --- async/autotests/asynctest.cpp | 2 -- async/src/async.h | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'async') diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index c507721..61ab8bc 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp @@ -340,8 +340,6 @@ void AsyncTest::testSyncEach() void AsyncTest::testJoinedEach() { - QFAIL("Crashes due to bad lifetime of Future"); - auto job1 = Async::start, int>( [](int v, Async::Future> &future) { new AsyncSimulator>(future, { v * 2 }); diff --git a/async/src/async.h b/async/src/async.h index c6ca9e7..7425604 100644 --- a/async/src/async.h +++ b/async/src/async.h @@ -499,9 +499,14 @@ private: auto job = otherJob; FutureWatcher *watcher = new FutureWatcher(); QObject::connect(watcher, &FutureWatcherBase::futureReady, - [watcher, &future]() { - Async::detail::copyFutureValue(watcher->future(), future); - future.setFinished(); + [watcher, future]() { + // FIXME: We pass future by value, because using reference causes the + // future to get deleted before this lambda is invoked, leading to crash + // in copyFutureValue() + // copy by value is const + auto outFuture = future; + Async::detail::copyFutureValue(watcher->future(), outFuture); + outFuture.setFinished(); delete watcher; }); watcher->setFuture(job.exec(in ...)); -- cgit v1.2.3