[pim/kleopatra] src: Fix memory leaks in system tray icon

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

Fix memory leaks in system tray icon

Destroying the system tray icon manually in the d'tor of the application's
Private class prevented the proper clean-up of the separators (!!!) of
the system tray icon's context menu. LeakSanitizer reported a leaked
QtWidgetsActionPrivate (and many more memory leaks) for each separator.
Setting the application as parent of the system tray icon fixes this
problem.

M  +1    -4    src/kleopatraapplication.cpp

https://invent.kde.org/pim/kleopatra/-/commit/82af2fb478b607fe9de982889f58e4a85b88b940

diff --git a/src/kleopatraapplication.cpp b/src/kleopatraapplication.cpp
index 2dd99d14b..747f22803 100644
--- a/src/kleopatraapplication.cpp
+++ b/src/kleopatraapplication.cpp
@@ -181,15 +181,12 @@ public:
     }
     ~Private()
     {
-#ifndef QT_NO_SYSTEMTRAYICON
-        delete sysTray;
-#endif
     }
     void setUpSysTrayIcon()
     {
 #ifndef QT_NO_SYSTEMTRAYICON
         Q_ASSERT(readerStatus);
-        sysTray = new SysTrayIcon();
+        sysTray = new SysTrayIcon{q};
         sysTray->setFirstCardWithNullPin(readerStatus->firstCardWithNullPin());
         connect(readerStatus.get(), &SmartCard::ReaderStatus::firstCardWithNullPinChanged, sysTray, &SysTrayIcon::setFirstCardWithNullPin);
 #endif
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.