qt,tests: Avoid leaking Context

* lang/qt/tests/t-import.cpp: Wrap Context*s in unique_ptr.
--

This fixes leaks found with -fsanitize=address.
This commit is contained in:
Ingo Klöcker 2023-01-31 09:10:57 +01:00
parent 5d07f8db77
commit 2b98585c89
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9

View File

@ -48,6 +48,8 @@
#include <QTemporaryDir> #include <QTemporaryDir>
#include <QTest> #include <QTest>
#include <memory>
using namespace QGpgME; using namespace QGpgME;
using namespace GpgME; using namespace GpgME;
@ -111,7 +113,7 @@ private Q_SLOTS:
QSignalSpy spy (this, SIGNAL(asyncDone())); QSignalSpy spy (this, SIGNAL(asyncDone()));
QVERIFY(spy.wait()); QVERIFY(spy.wait());
auto ctx = Context::createForProtocol(GpgME::OpenPGP); auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP));
GpgME::Error err; GpgME::Error err;
const auto key = ctx->key(keyFpr, err, false); const auto key = ctx->key(keyFpr, err, false);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());
@ -155,7 +157,7 @@ private Q_SLOTS:
QSignalSpy spy (this, SIGNAL(asyncDone())); QSignalSpy spy (this, SIGNAL(asyncDone()));
QVERIFY(spy.wait()); QVERIFY(spy.wait());
auto ctx = Context::createForProtocol(GpgME::OpenPGP); auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP));
GpgME::Error err; GpgME::Error err;
const auto key = ctx->key(keyFpr, err, false); const auto key = ctx->key(keyFpr, err, false);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());
@ -194,7 +196,7 @@ private Q_SLOTS:
QSignalSpy spy (this, SIGNAL(asyncDone())); QSignalSpy spy (this, SIGNAL(asyncDone()));
QVERIFY(spy.wait()); QVERIFY(spy.wait());
auto ctx = Context::createForProtocol(GpgME::OpenPGP); auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP));
GpgME::Error err; GpgME::Error err;
const auto key = ctx->key(keyFpr, err, false); const auto key = ctx->key(keyFpr, err, false);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());