[pim/kleopatra] src: Use wrap_unique helper for life-time managing exec'd QGpgME jobs

Ingo Klöcker <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 02bf0b5a7ef2ff5d177f1bff536a829d35d89e5c by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 29/07/2026 at 10:07.
Pushed by kloecker into branch 'master'.

Use wrap_unique helper for life-time managing exec'd QGpgME jobs

M  +2    -1    src/commands/exportsecretteamkeycommand.cpp
M  +3    -2    src/commands/importpaperkeycommand.cpp
M  +3    -1    src/smartcard/readerstatus.cpp

https://invent.kde.org/pim/kleopatra/-/commit/02bf0b5a7ef2ff5d177f1bff536a829d35d89e5c

diff --git a/src/commands/exportsecretteamkeycommand.cpp b/src/commands/exportsecretteamkeycommand.cpp
index a3a0be08a..8911661ea 100644
--- a/src/commands/exportsecretteamkeycommand.cpp
+++ b/src/commands/exportsecretteamkeycommand.cpp
@@ -10,6 +10,7 @@
 
 #include <utils/applicationstate.h>
 #include <utils/filedialog.h>
+#include <utils/memory-helpers.h>
 #include <utils/path-helper.h>
 
 #include <settings.h>
@@ -362,7 +363,7 @@ void ExportSecretTeamKeyCommand::Private::prepareExport(bool exportSecretSigning
 
     if (!exportSecretSigningSubkey && !signKeyFpr.isEmpty()) {
         // export the public signing subkey to share it together with the secret encryption subkey with the team members
-        std::unique_ptr<QGpgME::ExportJob> exportJob{QGpgME::openpgp()->publicKeyExportJob(format == OutputFormat::Armor)};
+        const auto exportJob = wrap_unique(QGpgME::openpgp()->publicKeyExportJob(format == OutputFormat::Armor));
 #if GPGME_VERSION_NUMBER >= QT_VERSION_CHECK(2, 0, 2) && QGPGME_VERSION >= QT_VERSION_CHECK(2, 0, 1)
         // export only the signing subkey (if gpgme is new enough); otherwise, the complete public team key is exported
         exportJob->setExportFilter("drop-subkey=fpr <> "_L1 + signKeyFpr);
diff --git a/src/commands/importpaperkeycommand.cpp b/src/commands/importpaperkeycommand.cpp
index 09c089c26..f687d941e 100644
--- a/src/commands/importpaperkeycommand.cpp
+++ b/src/commands/importpaperkeycommand.cpp
@@ -10,6 +10,8 @@
 
 #include "importpaperkeycommand.h"
 
+#include <utils/memory-helpers.h>
+
 #include <Libkleo/Formatting>
 #include <Libkleo/GnuPG>
 
@@ -121,9 +123,8 @@ void ImportPaperKeyCommand::postSuccessHook(QWidget *)
     auto data = secKey.readAll();
     secKey.close();
 
-    auto importjob = QGpgME::openpgp()->importJob();
+    const auto importjob = wrap_unique(QGpgME::openpgp()->importJob());
     auto result = importjob->exec(data);
-    delete importjob;
     if (result.error()) {
         d->error(Formatting::errorAsString(result.error()), errorCaption());
         return;
diff --git a/src/smartcard/readerstatus.cpp b/src/smartcard/readerstatus.cpp
index 1677d471f..030152c0a 100644
--- a/src/smartcard/readerstatus.cpp
+++ b/src/smartcard/readerstatus.cpp
@@ -13,6 +13,8 @@
 
 #include "deviceinfowatcher.h"
 
+#include <utils/memory-helpers.h>
+
 #include <Libkleo/Algorithm>
 #include <Libkleo/Assuan>
 #include <Libkleo/FileSystemWatcher>
@@ -810,7 +812,7 @@ static void importCardCertificates(std::shared_ptr<Context> &gpgAgent)
         }
         qCDebug(KLEOPATRA_LOG) << __func__ << "Retrieved certificate data from the card for slot" << certInfo.keyref;
 
-        const auto job = std::unique_ptr<QGpgME::ImportJob>(QGpgME::smime()->importJob());
+        const auto job = wrap_unique(QGpgME::smime()->importJob());
         const ImportResult result = job->exec(QByteArray::fromStdString(certificateData));
         if (result.error()) {
             qCDebug(KLEOPATRA_LOG) << __func__ << "Import of certificate data failed:" << result.error();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.