[utilities/krusader] app/BookMan: BookMan: Fix use-after-free problems in deferred bookmark search evaluation

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

BookMan: Fix use-after-free problems in deferred bookmark search evaluation

Replace raw pointers with QPointer inside the delayed `QTimer::singleShot`
lambda function that is used to restore active menu actions during a quick search.

Because `QTimer::singleShot` is executed in the next event loop iteration,
if the menu was rapidly closed or the action was deleted in the
background before the timer was triggered, the lambda function would
dereference a dangling pointer, resulting in a use-after-free abrupt termination.

By checking the validity of the `QPointer<QMenu>` and the `QPointer<QAction>`,
the deferred execution has to be safe.

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

M  +9    -7    app/BookMan/krbookmarkhandler.cpp

https://invent.kde.org/utilities/krusader/-/commit/e733bde6d14c6f0c93277c036dc137c2ee21df7a

diff --git a/app/BookMan/krbookmarkhandler.cpp b/app/BookMan/krbookmarkhandler.cpp
index 010aca6cf..c50ecf799 100644
--- a/app/BookMan/krbookmarkhandler.cpp
+++ b/app/BookMan/krbookmarkhandler.cpp
@@ -643,13 +643,15 @@ bool KrBookmarkHandler::eventFilter(QObject *obj, QEvent *ev)
             qDebug() << "Bookmark search: active action =" << _quickSearchMenu->activeAction();
 
             // fix automatic deactivation of current action due to spurious close event from submenu
-            auto quickSearchMenu = _quickSearchMenu;
-            auto activeAction = _quickSearchMenu->activeAction();
-            QTimer::singleShot(0, this, [=]() {
-                qDebug() << "Bookmark search: active action =" << quickSearchMenu->activeAction();
-                if (!quickSearchMenu->activeAction() && activeAction) {
-                    quickSearchMenu->setActiveAction(activeAction);
-                    qDebug() << "Bookmark search: restored active action =" << quickSearchMenu->activeAction();
+            QPointer<QMenu> quickSearchMenu = _quickSearchMenu;
+            QPointer<QAction> activeAction = _quickSearchMenu->activeAction();
+            QTimer::singleShot(0, this, [quickSearchMenu, activeAction]() {
+                if (quickSearchMenu && activeAction) {
+                    qDebug() << "Bookmark search: active action =" << quickSearchMenu->activeAction();
+                    if (!quickSearchMenu->activeAction()) {
+                        quickSearchMenu->setActiveAction(activeAction);
+                        qDebug() << "Bookmark search: restored active action =" << quickSearchMenu->activeAction();
+                    }
                 }
             });
         }
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.