summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qfutureinterface.h
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-10-09 11:01:16 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-10-13 17:04:16 +0200
commitba511b2fa4782d6618a5261bbbd50f0c57266a3a (patch)
tree62dd28d3ce8a8fd540e50726b648c989be818424 /src/corelib/thread/qfutureinterface.h
parent1ae15edd7e7ec4bd96d3a9a4d6b5793c7f7e8830 (diff)
Reject overwrites by the same index in QPromise::addResult()
One can call addResult(value, index) twice and consequently set the value twice by the same index. This seems rather strange and probably should not be allowed. This commit rejects setting results when there's already a valid result by that index. Consequently, this fixes memory leaks caused by N-times-called addResult(..., index) Fixes: QTBUG-86828 Change-Id: I77494f2cb73ce727ffad721cfcdcaa420899eb25 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/thread/qfutureinterface.h')
-rw-r--r--src/corelib/thread/qfutureinterface.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h
index 6c7c511cc07..9296c63f0b5 100644
--- a/src/corelib/thread/qfutureinterface.h
+++ b/src/corelib/thread/qfutureinterface.h
@@ -270,11 +270,12 @@ inline void QFutureInterface<T>::reportResult(const T *result, int index)
if (store.filterMode()) {
const int resultCountBefore = store.count();
- store.addResult<T>(index, result);
- this->reportResultsReady(resultCountBefore, store.count());
+ if (store.addResult<T>(index, result) != -1)
+ this->reportResultsReady(resultCountBefore, store.count());
} else {
const int insertIndex = store.addResult<T>(index, result);
- this->reportResultsReady(insertIndex, insertIndex + 1);
+ if (insertIndex != -1)
+ this->reportResultsReady(insertIndex, insertIndex + 1);
}
}
@@ -289,7 +290,8 @@ void QFutureInterface<T>::reportAndMoveResult(T &&result, int index)
const int oldResultCount = store.count();
const int insertIndex = store.moveResult(index, std::forward<T>(result));
- if (!store.filterMode() || oldResultCount < store.count()) // Let's make sure it's not in pending results.
+ // Let's make sure it's not in pending results.
+ if (insertIndex != -1 && (!store.filterMode() || oldResultCount < store.count()))
reportResultsReady(insertIndex, store.count());
}
@@ -317,11 +319,12 @@ inline void QFutureInterface<T>::reportResults(const QList<T> &_results, int beg
if (store.filterMode()) {
const int resultCountBefore = store.count();
- store.addResults(beginIndex, &_results, count);
- this->reportResultsReady(resultCountBefore, store.count());
+ if (store.addResults(beginIndex, &_results, count) != -1)
+ this->reportResultsReady(resultCountBefore, store.count());
} else {
const int insertIndex = store.addResults(beginIndex, &_results, count);
- this->reportResultsReady(insertIndex, insertIndex + _results.count());
+ if (insertIndex != -1)
+ this->reportResultsReady(insertIndex, insertIndex + _results.count());
}
}