Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Teubner <435950+c4rlo@users.noreply.github.com>2019-12-21 17:25:17 +0300
committerJonathan White <support@dmapps.us>2019-12-21 17:25:17 +0300
commitc70ebe6dce3c23a5090a102a4e9d5fb05838401d (patch)
tree6e634f10d2bf81571e0b4ce749db625d35c86ada /tests/TestOpVaultReader.cpp
parentc0f29cc790dc64b574229e9506d1d581cfbdb511 (diff)
Fix memory leaks (mostly) in tests (#3922)
This makes most tests run successfully with asan. The GUI tests still have a bunch of leaks, some from library code, and some that look real but which I didn't immediately manage to figure out. * TestOpVaultReader: use QSharedPointer
Diffstat (limited to 'tests/TestOpVaultReader.cpp')
-rw-r--r--tests/TestOpVaultReader.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/tests/TestOpVaultReader.cpp b/tests/TestOpVaultReader.cpp
index af332fd32..15f30f2c9 100644
--- a/tests/TestOpVaultReader.cpp
+++ b/tests/TestOpVaultReader.cpp
@@ -49,24 +49,24 @@ QPair<QString, QString>* split1PTextExportKV(QByteArray& line)
return new QPair<QString, QString>(k, v);
}
-QJsonArray* read1PasswordTextExport(QFile& f)
+QSharedPointer<QJsonArray> read1PasswordTextExport(QFile& f)
{
- auto result = new QJsonArray;
- auto current = new QJsonObject;
-
if (!f.open(QIODevice::ReadOnly)) {
qCritical("Unable to open your text export file for reading");
- return nullptr;
+ return {};
}
+ auto result = QSharedPointer<QJsonArray>::create();
+ QJsonObject current;
+
while (!f.atEnd()) {
auto line = f.readLine(1024);
if (line.size() == 1 and line[0] == '\n') {
- if (!current->isEmpty()) {
- result->append(*current);
+ if (!current.isEmpty()) {
+ result->append(current);
}
- current = new QJsonObject;
+ current = QJsonObject();
continue;
}
const auto kv = split1PTextExportKV(line);
@@ -95,14 +95,14 @@ QJsonArray* read1PasswordTextExport(QFile& f)
}
}
auto v = lines.join("");
- (*current)[k] = v;
+ current[k] = v;
} else {
- (*current)[k] = kv->second;
+ current[k] = kv->second;
}
delete kv;
}
- if (!current->isEmpty()) {
- result->append(*current);
+ if (!current.isEmpty()) {
+ result->append(current);
}
f.close();
@@ -120,10 +120,9 @@ void TestOpVaultReader::initTestCase()
m_password = "freddy";
QFile testData(m_opVaultTextExportPath);
- QJsonArray* data = read1PasswordTextExport(testData);
+ auto data = read1PasswordTextExport(testData);
QVERIFY(data);
QCOMPARE(data->size(), 27);
- delete data;
m_categoryMap.insert("001", "Login");
m_categoryMap.insert("002", "Credit Card");
@@ -149,9 +148,9 @@ void TestOpVaultReader::testReadIntoDatabase()
{
QDir opVaultDir(m_opVaultPath);
- auto reader = new OpVaultReader();
- auto db = reader->readDatabase(opVaultDir, m_password);
- QVERIFY2(!reader->hasError(), qPrintable(reader->errorString()));
+ OpVaultReader reader;
+ QScopedPointer<Database> db(reader.readDatabase(opVaultDir, m_password));
+ QVERIFY2(!reader.hasError(), qPrintable(reader.errorString()));
QVERIFY(db);
QVERIFY(!db->children().isEmpty());
@@ -179,7 +178,6 @@ void TestOpVaultReader::testReadIntoDatabase()
QUuid u = Tools::hexToUuid(value["uuid"].toString());
objectsByUuid[u] = value;
}
- delete testData;
QCOMPARE(objectsByUuid.size(), 27);
for (QUuid u : objectsByUuid.keys()) {
@@ -240,11 +238,11 @@ void TestOpVaultReader::testKeyDerivation()
void TestOpVaultReader::testBandEntry1()
{
- auto reader = new OpVaultReader();
+ OpVaultReader reader;
QByteArray json(R"({"hello": "world"})");
QJsonDocument doc = QJsonDocument::fromJson(json);
QJsonObject data;
QByteArray entryKey;
QByteArray entryHmacKey;
- QVERIFY(!reader->decryptBandEntry(doc.object(), data, entryKey, entryHmacKey));
+ QVERIFY(!reader.decryptBandEntry(doc.object(), data, entryKey, entryHmacKey));
}