From 714830f8dda873fbefa6de9704c90220e16a6133 Mon Sep 17 00:00:00 2001 From: Sebastian Englbrecht Date: Sat, 23 May 2026 17:40:25 +0200 Subject: dolphinview,mountpointobserver: kill in-flight KIO jobs in destructor Both objects start KIO jobs that can outlive the object if it is destroyed before the job finishes. Store the pending job and call kill(Quietly) in the destructor to avoid leaks and dangling callbacks. --- src/statusbar/mountpointobserver.cpp | 18 +++++++++++++----- src/statusbar/mountpointobserver.h | 6 ++++-- src/views/dolphinview.cpp | 3 +++ 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/statusbar/mountpointobserver.cpp b/src/statusbar/mountpointobserver.cpp index 67d341b3d..231ea72e7 100644 --- a/src/statusbar/mountpointobserver.cpp +++ b/src/statusbar/mountpointobserver.cpp @@ -8,8 +8,6 @@ #include "mountpointobservercache.h" -#include - MountPointObserver::MountPointObserver(const QUrl &url, QObject *parent) : QObject(parent) , m_url(url) @@ -17,6 +15,13 @@ MountPointObserver::MountPointObserver(const QUrl &url, QObject *parent) { } +MountPointObserver::~MountPointObserver() +{ + if (m_pendingJob) { + m_pendingJob->kill(KJob::Quietly); + } +} + MountPointObserver *MountPointObserver::observerForUrl(const QUrl &url) { MountPointObserver *observer = MountPointObserverCache::instance()->observerForUrl(url); @@ -27,10 +32,13 @@ void MountPointObserver::update() { if (m_referenceCount == 0) { delete this; - } else { - KIO::FileSystemFreeSpaceJob *job = KIO::fileSystemFreeSpace(m_url); - connect(job, &KJob::result, this, &MountPointObserver::freeSpaceResult); + return; + } + if (m_pendingJob) { + m_pendingJob->kill(KJob::Quietly); } + m_pendingJob = KIO::fileSystemFreeSpace(m_url); + connect(m_pendingJob, &KJob::result, this, &MountPointObserver::freeSpaceResult); } void MountPointObserver::freeSpaceResult(KJob *job) diff --git a/src/statusbar/mountpointobserver.h b/src/statusbar/mountpointobserver.h index 7c146c7a0..b2ca863e0 100644 --- a/src/statusbar/mountpointobserver.h +++ b/src/statusbar/mountpointobserver.h @@ -7,9 +7,10 @@ #ifndef MOUNTPOINTOBSERVER_H #define MOUNTPOINTOBSERVER_H -#include +#include #include +#include #include /** @@ -41,7 +42,7 @@ class MountPointObserver : public QObject Q_OBJECT explicit MountPointObserver(const QUrl &url, QObject *parent = nullptr); - ~MountPointObserver() override = default; + ~MountPointObserver() override; public: /** @@ -90,6 +91,7 @@ private Q_SLOTS: private: const QUrl m_url; int m_referenceCount; + QPointer m_pendingJob; friend class MountPointObserverCache; }; diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 4747b5ecc..74c5ecd23 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -276,6 +276,9 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) DolphinView::~DolphinView() { + if (m_statJobForStatusBarText) { + m_statJobForStatusBarText->kill(KJob::Quietly); + } disconnect(m_container->controller(), &KItemListController::modelChanged, this, &DolphinView::slotModelChanged); } -- cgit v1.3.1