Qt: Create TestPassphraseProvider on stack
authorAndre Heinecke <aheinecke@intevation.de>
Wed, 10 Aug 2016 10:05:32 +0000 (12:05 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Wed, 10 Aug 2016 10:07:56 +0000 (12:07 +0200)
* lang/qt/tests/t-encrypt.cpp, lang/qt/tests/t-tofuinfo.cpp: Create
TestPassphraseProvider on stack.

--
Context does not delete the provider. This fixes ASAN errors.

lang/qt/tests/t-encrypt.cpp
lang/qt/tests/t-tofuinfo.cpp

index b0b6994..c6fcaa2 100644 (file)
@@ -71,7 +71,8 @@ private Q_SLOTS:
 
         /* Now decrypt */
         auto ctx = Context::createForProtocol(OpenPGP);
-        ctx->setPassphraseProvider(new TestPassphraseProvider);
+        TestPassphraseProvider provider;
+        ctx->setPassphraseProvider(&provider);
         ctx->setPinentryMode(Context::PinentryLoopback);
         auto decJob = new QGpgMEDecryptJob(ctx);
         QByteArray plainText;
@@ -84,7 +85,8 @@ private Q_SLOTS:
     void testSymmetricEncryptDecrypt()
     {
         auto ctx = Context::createForProtocol(OpenPGP);
-        ctx->setPassphraseProvider(new TestPassphraseProvider);
+        TestPassphraseProvider provider;
+        ctx->setPassphraseProvider(&provider);
         ctx->setPinentryMode(Context::PinentryLoopback);
         ctx->setArmor(true);
         ctx->setTextMode(true);
@@ -99,7 +101,7 @@ private Q_SLOTS:
         killAgent(mDir.path());
 
         auto ctx2 = Context::createForProtocol(OpenPGP);
-        ctx2->setPassphraseProvider(new TestPassphraseProvider);
+        ctx2->setPassphraseProvider(&provider);
         ctx2->setPinentryMode(Context::PinentryLoopback);
         auto decJob = new QGpgMEDecryptJob(ctx2);
         QByteArray plainText;
index 8331092..3072f0f 100644 (file)
@@ -73,7 +73,8 @@ class TofuInfoTest: public QGpgMETest
     void signAndVerify(const QString &what, const GpgME::Key &key, int expected)
     {
         Context *ctx = Context::createForProtocol(OpenPGP);
-        ctx->setPassphraseProvider(new TestPassphraseProvider);
+        TestPassphraseProvider provider;
+        ctx->setPassphraseProvider(&provider);
         ctx->setPinentryMode(Context::PinentryLoopback);
         auto *job = new QGpgMESignJob(ctx);