[utilities/krusader] app/BookMan: BookMan: Fix a child QMenu leak in populate()

Toni Asensi Esteve <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 9ed504bc2e9f4dfd8027f96106fe6fd1a546d60d by Toni Asensi Esteve.
Committed on 16/08/2026 at 22:14.
Pushed by asensi into branch 'master'.

BookMan: Fix a child QMenu leak in populate()

Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/193

M  +13   -0    app/BookMan/krbookmarkhandler.cpp

https://invent.kde.org/utilities/krusader/-/commit/9ed504bc2e9f4dfd8027f96106fe6fd1a546d60d

diff --git a/app/BookMan/krbookmarkhandler.cpp b/app/BookMan/krbookmarkhandler.cpp
index c123f617b..70cbd5f91 100644
--- a/app/BookMan/krbookmarkhandler.cpp
+++ b/app/BookMan/krbookmarkhandler.cpp
@@ -412,6 +412,19 @@ void KrBookmarkHandler::populate(QMenu *menu)
         _mainBookmarkPopup->removeAction(_quickSearchAction);
     }
     _mainBookmarkPopup = menu;
+
+    // In order to prevent memory leaks:
+    // QMenu::clear() deletes actions, but it does *not* delete
+    // the dynamically-allocated child QMenus. We must explicitly
+    // delete them in order to prevent a fast proliferation of
+    // top-level widgets that are not properly cleaned up
+    const auto actions = menu->actions();
+    for (QAction *act : actions) {
+        if (QMenu *subMenu = act->menu()) {
+            delete subMenu;
+        }
+    }
+
     menu->clear();
     _specialBookmarks.clear();
     buildMenu(_root, menu);
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.