summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-07-15 23:02:34 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-07-19 04:52:28 +0000
commit69d767bec265587a5645a08f14bb7e7540f01867 (patch)
tree8dbffdd417b42bd96a957f3e5ec8e9253e4c47ce /tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
parent74707948652d1b251b2296ce0b3a515b2ddbcc08 (diff)
tst_QHostInfo: fix mem-leaks in threadSafetyAsynchronousAPI()
Allocate participating threads and objects on the stack, not the heap. As a drive-by, port from QList to C arrays (never use a dynamically-sized container for statically-sized data™). Code predates the public history, all active branches are affected. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: If8def658c1c7b505074938d637e78ad2d1f9fd57 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp')
-rw-r--r--tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
index e6704c3623..195cf972d9 100644
--- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
@@ -43,7 +43,6 @@
#define TEST_DOMAIN ".test.qt-project.org"
-
class tst_QHostInfo : public QObject
{
Q_OBJECT
@@ -552,24 +551,22 @@ void tst_QHostInfo::threadSafetyAsynchronousAPI()
{
const int nattempts = 10;
const int lookupsperthread = 10;
- QList<QThread*> threads;
- QList<LookupReceiver*> receivers;
+ QThread threads[nattempts];
+ LookupReceiver receivers[nattempts];
for (int i = 0; i < nattempts; ++i) {
- QThread* thread = new QThread;
- LookupReceiver* receiver = new LookupReceiver;
+ QThread *thread = &threads[i];
+ LookupReceiver *receiver = &receivers[i];
receiver->numrequests = lookupsperthread;
- receivers.append(receiver);
receiver->moveToThread(thread);
connect(thread, SIGNAL(started()), receiver, SLOT(start()));
thread->start();
- threads.append(thread);
}
- for (int k = threads.size() - 1; k >= 0; --k)
- QVERIFY(threads.at(k)->wait(60000));
- foreach (LookupReceiver* receiver, receivers) {
- QCOMPARE(receiver->result.error(), QHostInfo::NoError);
- QCOMPARE(receiver->result.addresses().at(0).toString(), QString("192.0.2.1"));
- QCOMPARE(receiver->numrequests, 0);
+ for (int k = nattempts - 1; k >= 0; --k)
+ QVERIFY(threads[k].wait(60000));
+ for (LookupReceiver &receiver : receivers) {
+ QCOMPARE(receiver.result.error(), QHostInfo::NoError);
+ QCOMPARE(receiver.result.addresses().at(0).toString(), QString("192.0.2.1"));
+ QCOMPARE(receiver.numrequests, 0);
}
}