[libraries/baloo-widgets] src/tagsfileitemactionplugin: tags action: hold the file metadata in a unique pointer

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 686fcc768f381456e9fd275e94ce466931f08dc7 by Méven Car.
Committed on 16/08/2026 at 09:57.
Pushed by meven into branch 'master'.

tags action: hold the file metadata in a unique pointer

The plugin reads the metadata of the file a menu is built for into a raw
pointer member. Building a menu for the next file overwrote that pointer
without freeing what it held, so every menu after the first left one
UserMetaData behind. Only the last one was freed, when the plugin was
destroyed at the end of the session.

Hold it in a std::unique_ptr, so reading the metadata of another file
releases the previous one and the plugin needs no destructor of its own.

M  +1    -6    src/tagsfileitemactionplugin/tagsfileitemaction.cpp
M  +3    -2    src/tagsfileitemactionplugin/tagsfileitemaction.h

https://invent.kde.org/libraries/baloo-widgets/-/commit/686fcc768f381456e9fd275e94ce466931f08dc7

diff --git a/src/tagsfileitemactionplugin/tagsfileitemaction.cpp b/src/tagsfileitemactionplugin/tagsfileitemaction.cpp
index eef9ca1..6267f28 100644
--- a/src/tagsfileitemactionplugin/tagsfileitemaction.cpp
+++ b/src/tagsfileitemactionplugin/tagsfileitemaction.cpp
@@ -29,11 +29,6 @@ TagsFileItemAction::TagsFileItemAction(QObject *parent, const QVariantList &)
 {
 }
 
-TagsFileItemAction::~TagsFileItemAction()
-{
-    delete m_metaData;
-}
-
 QList<QAction *> TagsFileItemAction::actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget)
 {
     // This action only applies to a single file. Bail out for multiple
@@ -47,7 +42,7 @@ QList<QAction *> TagsFileItemAction::actions(const KFileItemListProperties &file
         return {};
     }
 
-    m_metaData = new KFileMetaData::UserMetaData(filePath);
+    m_metaData = std::make_unique<KFileMetaData::UserMetaData>(filePath);
     if (!m_metaData->isSupported()) {
         return {};
     }
diff --git a/src/tagsfileitemactionplugin/tagsfileitemaction.h b/src/tagsfileitemactionplugin/tagsfileitemaction.h
index 52545eb..1fc69c3 100644
--- a/src/tagsfileitemactionplugin/tagsfileitemaction.h
+++ b/src/tagsfileitemactionplugin/tagsfileitemaction.h
@@ -12,6 +12,8 @@
 #include <KFileItemListProperties>
 #include <KFileMetaData/UserMetaData>
 
+#include <memory>
+
 class QAction;
 class QWidget;
 
@@ -20,11 +22,10 @@ class TagsFileItemAction : public KAbstractFileItemActionPlugin
     Q_OBJECT
 public:
     TagsFileItemAction(QObject *parent, const QVariantList &args);
-    ~TagsFileItemAction() override;
     QList<QAction *> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override;
 
 private:
-    KFileMetaData::UserMetaData *m_metaData = nullptr;
+    std::unique_ptr<KFileMetaData::UserMetaData> m_metaData;
     KCoreDirLister m_tagsLister;
 };
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.