diff options
| author | Sebastian Englbrecht <[email protected]> | 2026-05-23 17:40:25 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-05-28 08:59:00 +0000 |
| commit | 714830f8dda873fbefa6de9704c90220e16a6133 (patch) | |
| tree | a5458c0da6e0569f99011447d948d3368082d683 /src/statusbar | |
| parent | 8f7ab9d4b7ecc71083e2d7e03863857b1cfdea54 (diff) | |
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.
Diffstat (limited to 'src/statusbar')
| -rw-r--r-- | src/statusbar/mountpointobserver.cpp | 18 | ||||
| -rw-r--r-- | src/statusbar/mountpointobserver.h | 6 |
2 files changed, 17 insertions, 7 deletions
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 <KIO/FileSystemFreeSpaceJob> - 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 <KIO/Job> +#include <KIO/FileSystemFreeSpaceJob> #include <QObject> +#include <QPointer> #include <QUrl> /** @@ -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<KIO::FileSystemFreeSpaceJob> m_pendingJob; friend class MountPointObserverCache; }; |
