summaryrefslogtreecommitdiffstats
path: root/async/src
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-19 12:13:29 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-19 12:13:29 +0200
commit12d24dabb8763deed1ab2372d7b69765822b14a5 (patch)
treefdd3b0cb20ff5410a0b41b613d9f5c69fd10f76c /async/src
parent462d2999f0171452ecb6fafb52c7244008f536eb (diff)
downloadsink-12d24dabb8763deed1ab2372d7b69765822b14a5.tar.gz
sink-12d24dabb8763deed1ab2372d7b69765822b14a5.zip
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....
Diffstat (limited to 'async/src')
-rw-r--r--async/src/async.h13
1 files changed, 7 insertions, 6 deletions
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<PrevOut, Out, In>::run(const ExecutionPtr &execution)
718 } 718 }
719 719
720 for (auto arg : prevFuture->value()) { 720 for (auto arg : prevFuture->value()) {
721 Async::Future<Out> future; 721 //We have to manually manage the lifetime of these temporary futures
722 EachExecutor<PrevOut, Out, In>::mFunc(arg, future); 722 Async::Future<Out> *future = new Async::Future<Out>();
723 EachExecutor<PrevOut, Out, In>::mFunc(arg, *future);
723 auto fw = new Async::FutureWatcher<Out>(); 724 auto fw = new Async::FutureWatcher<Out>();
724 mFutureWatchers.append(fw); 725 mFutureWatchers.append(fw);
725 QObject::connect(fw, &Async::FutureWatcher<Out>::futureReady, 726 QObject::connect(fw, &Async::FutureWatcher<Out>::futureReady,
726 [out, fw, this]() { 727 [out, fw, this, future]() {
727 auto future = fw->future(); 728 assert(fw->future().isFinished());
728 assert(future.isFinished());
729 const int index = mFutureWatchers.indexOf(fw); 729 const int index = mFutureWatchers.indexOf(fw);
730 assert(index > -1); 730 assert(index > -1);
731 mFutureWatchers.removeAt(index); 731 mFutureWatchers.removeAt(index);
@@ -734,8 +734,9 @@ void EachExecutor<PrevOut, Out, In>::run(const ExecutionPtr &execution)
734 out->setFinished(); 734 out->setFinished();
735 } 735 }
736 delete fw; 736 delete fw;
737 delete future;
737 }); 738 });
738 fw->setFuture(future); 739 fw->setFuture(*future);
739 } 740 }
740} 741}
741 742