[utilities/krusader] app/BookMan: BookMan: Fix use-after-free problems when bookmarks change while its menu is open
Toni Asensi Esteve <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 37f75b4f57f5397933099dfb1f43938dce34db0e by Toni Asensi Esteve.
Committed on 16/08/2026 at 22:14.
Pushed by asensi into branch 'master'.
BookMan: Fix use-after-free problems when bookmarks change while its menu is open
Prevent an abrupt termination caused by background modifications to
the bookmarks file while the user is actively browsing the bookmarks menu
of Krusader.
Previously, if the `krbookmarks.xml` file was modified externally
(e.g. triggering the `KBookmarkManager::changed` signal), `importFromFile()`
would synchronously clear and delete the internal `KrBookmark` tree.
However, if `_mainBookmarkPopup` was currently visible on screen, it
retained the visual actions backed by the now-deleted memory pointers,
leading to a use-after-free abrupt termination when the user interacted with it.
By detecting if the menu is actively visible, and immediately forcing
a `populate()` call, the UI now rebuilds itself with the recently allocated
pointers before the user can click a stale action.
Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/193
M +6 -0 app/BookMan/krbookmarkhandler.cpp
https://invent.kde.org/utilities/krusader/-/commit/37f75b4f57f5397933099dfb1f43938dce34db0e
diff --git a/app/BookMan/krbookmarkhandler.cpp b/app/BookMan/krbookmarkhandler.cpp
index e4f652d75..3f5e1d027 100644
--- a/app/BookMan/krbookmarkhandler.cpp
+++ b/app/BookMan/krbookmarkhandler.cpp
@@ -619,6 +619,12 @@ void KrBookmarkHandler::clearBookmarks(KrBookmark *root, bool removeBookmarks)
void KrBookmarkHandler::bookmarksChanged(const QString &)
{
importFromFile();
+
+ // Refresh the active menu if it is currently visible to the user
+ // to prevent dangling pointers in the UI
+ if (_mainBookmarkPopup && !_mainBookmarkPopup->isHidden()) {
+ populate(_mainBookmarkPopup);
+ }
}
bool KrBookmarkHandler::eventFilter(QObject *obj, QEvent *ev)