From 12d24dabb8763deed1ab2372d7b69765822b14a5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 19 Apr 2015 12:13:29 +0200 Subject: Async: Ensure the future passed by reference to the handler remains valid. The reference used to become invalid during execution of the handler, leading to subtle errors (the job just never finished). Unfortunately I failed to write a test that catches this, as the test always seems to work anyways.... --- async/src/async.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'async/src') diff --git a/async/src/async.h b/async/src/async.h index 73eeaa0..a72d058 100644 --- a/async/src/async.h +++ b/async/src/async.h @@ -718,14 +718,14 @@ void EachExecutor::run(const ExecutionPtr &execution) } for (auto arg : prevFuture->value()) { - Async::Future future; - EachExecutor::mFunc(arg, future); + //We have to manually manage the lifetime of these temporary futures + Async::Future *future = new Async::Future(); + EachExecutor::mFunc(arg, *future); auto fw = new Async::FutureWatcher(); mFutureWatchers.append(fw); QObject::connect(fw, &Async::FutureWatcher::futureReady, - [out, fw, this]() { - auto future = fw->future(); - assert(future.isFinished()); + [out, fw, this, future]() { + assert(fw->future().isFinished()); const int index = mFutureWatchers.indexOf(fw); assert(index > -1); mFutureWatchers.removeAt(index); @@ -734,8 +734,9 @@ void EachExecutor::run(const ExecutionPtr &execution) out->setFinished(); } delete fw; + delete future; }); - fw->setFuture(future); + fw->setFuture(*future); } } -- cgit v1.2.3