diff options
author | Morten Sørvig <msorvig@trolltech.com> | 2009-05-05 12:29:44 (GMT) |
---|---|---|
committer | Morten Sørvig <msorvig@trolltech.com> | 2009-05-05 12:29:44 (GMT) |
commit | 8be2b24705da4bce99b3a3d588aedcfe2eb3f886 (patch) | |
tree | 76dd284f996bcade6ddb04d26cdf44baac7a561c /tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp | |
parent | c03a4544fa3c1400fef3f1ad847bc3c65e660de7 (diff) | |
download | Qt-8be2b24705da4bce99b3a3d588aedcfe2eb3f886.zip Qt-8be2b24705da4bce99b3a3d588aedcfe2eb3f886.tar.gz Qt-8be2b24705da4bce99b3a3d588aedcfe2eb3f886.tar.bz2 |
Fix memory leak in QFuture
The held results were not cleared by QFutureInterface::operator=(QFutureInterface)
Add call to resultStore().clear(), similar to the destructor.
This needs to be done in the header since we know the template type here.
Task-number: 252208
Reviewed-by: brad
Diffstat (limited to 'tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp')
-rw-r--r-- | tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp index 139eb6e..116f46e 100644 --- a/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -74,6 +74,7 @@ private slots: void incrementalResults(); void noDetatch(); void stlContainers(); + void qFutureAssignmentLeak(); void stressTest(); public slots: void throttling(); @@ -2323,6 +2324,36 @@ void tst_map::stlContainers() #endif } +InstanceCounter ic_fn(const InstanceCounter & ic) +{ + return InstanceCounter(ic); +}; + +// Verify that held results are deleted when a future is +// assigned over with operator == +void tst_map::qFutureAssignmentLeak() +{ + currentInstanceCount = 0; + peakInstanceCount = 0; + QFuture<InstanceCounter> future; + { + QList<InstanceCounter> list; + for (int i=0;i<1000;++i) + list += InstanceCounter(); + future = QtConcurrent::mapped(list, ic_fn); + future.waitForFinished(); + + future = QtConcurrent::mapped(list, ic_fn); + future.waitForFinished(); + + future = QtConcurrent::mapped(list, ic_fn); + future.waitForFinished(); + } + + QCOMPARE(int(currentInstanceCount), 1000); + future = QFuture<InstanceCounter>(); + QCOMPARE(int(currentInstanceCount), 0); +} inline void increment(int &num) { |