[utilities/krusader] app/Dialogs: PopularUrls: Fix a memory leak

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

PopularUrls: Fix a memory leak

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

M  +13   -2    app/Dialogs/popularurls.cpp
M  +3    -0    app/Dialogs/popularurls.h

https://invent.kde.org/utilities/krusader/-/commit/0c55355e1276421d840e671b2620929bd4af2219

diff --git a/app/Dialogs/popularurls.cpp b/app/Dialogs/popularurls.cpp
index b25136cc2..1940e2dd6 100644
--- a/app/Dialogs/popularurls.cpp
+++ b/app/Dialogs/popularurls.cpp
@@ -155,12 +155,23 @@ void PopularUrls::addUrl(const QUrl &url)
     relocateIfNeeded(pnode);
 
     // too many urls?
-    if (count > maxUrls)
-        removeNode(tail);
+    if (count > maxUrls) {
+        deleteNode(tail);
+    }
 
     // dumpList();
 }
 
+void PopularUrls::deleteNode(UrlNodeP node)
+{
+    // Remove the url from the `ranks` QHash
+    ranks.remove(node->url.url());
+    // Unlink the node from the list
+    removeNode(node);
+    // Free memory
+    delete node;
+}
+
 // checks if 'node' needs to be bumped-up the ranking list and does it if needed
 void PopularUrls::relocateIfNeeded(UrlNodeP node)
 {
diff --git a/app/Dialogs/popularurls.h b/app/Dialogs/popularurls.h
index 18fcf35f1..1d0fad639 100644
--- a/app/Dialogs/popularurls.h
+++ b/app/Dialogs/popularurls.h
@@ -51,6 +51,9 @@ public slots:
     void showDialog();
 
 protected:
+    // Remove a node from the list and delete it from memory
+    void deleteNode(UrlNodeP node);
+
     // NOTE: the following methods append/insert/remove a node to the list
     // but NEVER free memory or allocate memory!
     void appendNode(UrlNodeP node);
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.