summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2022-03-08 18:49:39 +0100
committerRobert Griebl <robert.griebl@qt.io>2022-03-22 00:31:25 +0100
commitaa9c353420c515b0673287606dbc0916a2d52a05 (patch)
tree6afb51e6d3c830510056215525a8acf95d030e3e
parentff2c77ad7332a071ca8190ea373a4292fa312b24 (diff)
downloadqtapplicationmanager-aa9c353420c515b0673287606dbc0916a2d52a05.tar.gz
Fix memory leaks in the auto tests
Found by using the Linux/gcc/ASAN leak checker. Change-Id: Id9e2aae8c79b0d1ae71f90e7fbbb876ff9076def Reviewed-by: Bernd Weimer <bernd.weimer@qt.io> (cherry picked from commit 4178fd06ebf3af17019b29d7010a2b81571bec91) Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r--tests/runtime/tst_runtime.cpp22
-rw-r--r--tests/yaml/tst_yaml.cpp9
2 files changed, 18 insertions, 13 deletions
diff --git a/tests/runtime/tst_runtime.cpp b/tests/runtime/tst_runtime.cpp
index d64014e2..73a2f7a9 100644
--- a/tests/runtime/tst_runtime.cpp
+++ b/tests/runtime/tst_runtime.cpp
@@ -110,10 +110,10 @@ tst_Runtime::tst_Runtime()
void tst_Runtime::factory()
{
- RuntimeFactory *rf = RuntimeFactory::instance();
+ QScopedPointer<RuntimeFactory> rf { RuntimeFactory::instance() };
QVERIFY(rf);
- QVERIFY(rf == RuntimeFactory::instance());
+ QVERIFY(rf.get() == RuntimeFactory::instance());
QVERIFY(rf->runtimeIds().isEmpty());
QVERIFY(rf->registerRuntime(new TestRuntimeManager(qSL("foo"), qApp)));
@@ -136,20 +136,22 @@ void tst_Runtime::factory()
QCOMPARE(temp.write(yaml), yaml.size());
temp.close();
- Application *a = nullptr;
+ QScopedPointer<Application> a;
+ QScopedPointer<PackageInfo> pi;
+ QScopedPointer<Package> p;
try {
- PackageInfo *pi = PackageInfo::fromManifest(temp.fileName());
+ pi.reset(PackageInfo::fromManifest(temp.fileName()));
QVERIFY(pi);
- Package *p = new Package(pi);
- a = new Application(pi->applications().first(), p);
+ p.reset(new Package(pi.get()));
+ a.reset(new Application(pi->applications().constFirst(), p.get()));
} catch (const Exception &e) {
QVERIFY2(false, qPrintable(e.errorString()));
}
QVERIFY(a);
- AbstractRuntime *r = rf->create(nullptr, a);
+ QScopedPointer<AbstractRuntime> r { rf->create(nullptr, a.get()) };
QVERIFY(r);
- QVERIFY(r->application() == a);
+ QVERIFY(r->application() == a.get());
QVERIFY(r->manager()->inProcess());
QVERIFY(r->state() == Am::NotRunning);
QVERIFY(r->applicationProcessId() == 0);
@@ -166,10 +168,6 @@ void tst_Runtime::factory()
r->stop();
QVERIFY(r->state() == Am::NotRunning);
QVERIFY(!r->securityToken().isEmpty());
-
- delete r;
- delete rf;
- delete a;
}
QTEST_MAIN(tst_Runtime)
diff --git a/tests/yaml/tst_yaml.cpp b/tests/yaml/tst_yaml.cpp
index 8d7f022a..db0e4d86 100644
--- a/tests/yaml/tst_yaml.cpp
+++ b/tests/yaml/tst_yaml.cpp
@@ -309,6 +309,9 @@ void tst_Yaml::cache()
QVERIFY(ct2);
QCOMPARE(ct2->name, "cache2");
QCOMPARE(ct2->file, ":/data/cache2.yaml");
+
+ delete ct1;
+ delete ct2;
} catch (const Exception &e) {
QVERIFY2(false, e.what());
}
@@ -361,6 +364,8 @@ void tst_Yaml::mergedCache()
QVERIFY(ct);
QCOMPARE(ct->name, QFileInfo(files.last()).baseName());
QCOMPARE(ct->file, files.join(qSL(",")));
+
+ delete ct;
} catch (const Exception &e) {
QVERIFY2(false, e.what());
}
@@ -382,7 +387,9 @@ void tst_Yaml::mergedCache()
QTest::ignoreMessage(QtWarningMsg, "Failed to read Cache: cached file checksums do not match");
brokenCache.parse();
QVERIFY(brokenCache.parseReadFromCache());
- QCOMPARE(brokenCache.takeMergedResult()->value, qSL("foobar"));
+ CacheTest *ct = brokenCache.takeMergedResult();
+ QCOMPARE(ct->value, qSL("foobar"));
+ delete ct;
}
class YamlRunnable : public QRunnable