diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-09-24 10:48:33 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-09-28 15:48:17 +0200 |
commit | a6e1f67937c280961f7ec23b2a002ca7d057761d (patch) | |
tree | 8ca782fdd8960d035077d112d0caa34ba16e7fa2 /src/concurrent/qtconcurrentmapkernel.h | |
parent | b12d6c6a8ab5f7b01bdd2cb862a66a409700faa1 (diff) |
Fix QtConcurrent algorithms to work with temporary sequences
QtConcurrent algorithms are making an internal copy of the passed
sequence, to make sure it won't be destroyed before the execution
is finished. However, they were using iterators of the originally
passed sequence. So, if the original sequence is deleted, QtConcurrent
algorithms would use invalid iterators to a deleted sequence. This
might work with Qt containers thanks to implicit-sharing, but with
other containers will lead to unexpected results. Fixed them to work
on the internal copy of the original sequence.
Change-Id: I1d68692ed9746223c85f51bb05977bc1443b681d
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentmapkernel.h')
-rw-r--r-- | src/concurrent/qtconcurrentmapkernel.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/concurrent/qtconcurrentmapkernel.h b/src/concurrent/qtconcurrentmapkernel.h index 11be262628..0e6cfa4b9a 100644 --- a/src/concurrent/qtconcurrentmapkernel.h +++ b/src/concurrent/qtconcurrentmapkernel.h @@ -219,20 +219,19 @@ inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, Iterator begin, sequence we are working on. */ template <typename Sequence, typename Base, typename Functor> -struct SequenceHolder1 : public Base +struct SequenceHolder1 : private QtPrivate::SequenceHolder<Sequence>, public Base { SequenceHolder1(QThreadPool *pool, const Sequence &_sequence, Functor functor) - : Base(pool, _sequence.begin(), _sequence.end(), functor), sequence(_sequence) + : QtPrivate::SequenceHolder<Sequence>(_sequence), + Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor) { } - Sequence sequence; - void finish() override { Base::finish(); // Clear the sequence to make sure all temporaries are destroyed // before finished is signaled. - sequence = Sequence(); + this->sequence = Sequence(); } }; |