summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-01-24 15:57:07 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-25 00:55:18 +0000
commitf804be32d25baf506fdfb99a3e43b797cf43e769 (patch)
tree351dd2bb92d335312752892d5ba396126c56e358 /tests
parent4a6e31f78bcce48a2178f620bfcd0c44b5356940 (diff)
Fix memory leak in QtConcurrent::run when called with a NULL QThreadPool
QThreadPool automatically deletes the runnable after it finishes running the task. In case QThreadPool is nullptr, we should delete the runnable manually. This amends 87b93c29be02f0a7ff9424b5e2b6431e20bd4c40. Change-Id: Id7e4ed3d4d6de05990edf62e4099852983debc64 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 4cd8eeaf8c6a05f09bdbc92690b63f5233abdad0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
index 0ff98c42f5..ee13791652 100644
--- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
+++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
@@ -66,6 +66,7 @@ private slots:
void customPromise();
void nonDefaultConstructibleValue();
void nullThreadPool();
+ void nullThreadPoolNoLeak();
};
void light()
@@ -1589,5 +1590,27 @@ void tst_QtConcurrentRun::nullThreadPool()
QVERIFY(!isInvoked);
}
+struct LifetimeChecker
+{
+ LifetimeChecker() { ++count; }
+ LifetimeChecker(const LifetimeChecker &) { ++count; }
+ ~LifetimeChecker() { --count; }
+
+ void operator()() { }
+
+ static std::atomic<int> count;
+};
+std::atomic<int> LifetimeChecker::count = 0;
+
+void tst_QtConcurrentRun::nullThreadPoolNoLeak()
+{
+ {
+ QThreadPool *pool = nullptr;
+ auto future = run(pool, LifetimeChecker());
+ future.waitForFinished();
+ }
+ QCOMPARE(LifetimeChecker::count, 0);
+}
+
QTEST_MAIN(tst_QtConcurrentRun)
#include "tst_qtconcurrentrun.moc"