Commit 0ff09889 authored by Milian Wolff's avatar Milian Wolff
Browse files

Fix memory leaks in test_foregroundlock

Fixes LSAN reports:
```
Indirect leak of 7480 byte(s) in 55 object(s) allocated from:
    #0 0x7f45be2abf41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f45b148435a in QThread::QThread(QObject*) (/usr/lib/libQt5Core.so.5+0xcc35a)

Indirect leak of 6600 byte(s) in 55 object(s) allocated from:
    #0 0x7f45be2abf41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f45b14843bf in QThread::QThread(QObject*) (/usr/lib/libQt5Core.so.5+0xcc3bf)

Indirect leak of 5280 byte(s) in 55 object(s) allocated from:
    #0 0x7f45be2abf41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f45b148be25 in QWaitCondition::QWaitCondition() (/usr/lib/libQt5Core.so.5+0xd3e25)

Indirect leak of 880 byte(s) in 55 object(s) allocated from:
    #0 0x7f45be2abf41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x55ef2619f72a in KDevelop::TestForegroundLock::testTryLock() /home/milian/projects/kf5/src/extragear/kdevelop/kdevelop/kdevplatform/util/tests/test_foregroundlock.cpp:73
```
parent f23e0618
......@@ -25,6 +25,9 @@
#include <QRandomGenerator>
#endif
#include <memory>
#include <vector>
#include "../foregroundlock.h"
QTEST_MAIN(KDevelop::TestForegroundLock)
......@@ -68,23 +71,23 @@ void TestForegroundLock::testTryLock_data()
void TestForegroundLock::testTryLock()
{
QFETCH(int, numThreads);
QList<TryLockThread*> threads;
std::vector<std::unique_ptr<TryLockThread>> threads;
threads.reserve(numThreads);
for (int i = 0; i < numThreads; ++i) {
threads << new TryLockThread;
threads.push_back(std::make_unique<TryLockThread>());
}
ForegroundLock lock(true);
for (TryLockThread* thread : qAsConst(threads)) {
for (auto& thread : threads) {
thread->start();
}
lock.unlock();
while (true) {
const bool running = std::any_of(threads.constBegin(), threads.constEnd(), [](TryLockThread* thread) {
return thread->isRunning();
});
const bool running
= std::any_of(threads.cbegin(), threads.cend(), [](const auto& thread) { return thread->isRunning(); });
if (!running) {
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment