From bbc750f14abbb28ca900896fd4ab9790eea2a5af Mon Sep 17 00:00:00 2001 From: liyigang Date: Wed, 13 Nov 2024 14:07:39 +0800 Subject: [PATCH] fix: dde-file-manager copy crash,prevent memory leak in speed timer handling Fix memory management of QElapsedTimer objects in AbstractWorker: - Store deleted timers in speedtimerList instead of immediate deletion - Add cleanup of timer list in destructor using qDeleteAll - Maintain existing pause/resume functionality This change prevents potential memory leaks when pausing/resuming file operations while properly managing timer resources. Log: dde-file-manager copy crash Bug: https://pms.uniontech.com/bug-view-279983.html --- .../fileoperations/fileoperationutils/abstractworker.cpp | 4 +++- .../fileoperations/fileoperationutils/abstractworker.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.cpp index 17c6370add..fbbb57da04 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.cpp @@ -121,7 +121,7 @@ void AbstractWorker::pause() return; if (speedtimer) { elapsed += speedtimer->elapsed(); - delete speedtimer; + speedtimerList.append(speedtimer); speedtimer = nullptr; JobInfoPointer info(new QMap); info->insert(AbstractJobHandler::NotifyInfoKey::kJobtypeKey, QVariant::fromValue(jobType)); @@ -667,6 +667,8 @@ AbstractWorker::~AbstractWorker() delete speedtimer; speedtimer = nullptr; } + + qDeleteAll(speedtimerList); } /*! diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.h b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.h index bca6eb161f..1306f6a8f5 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.h +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/abstractworker.h @@ -194,6 +194,7 @@ protected slots: std::atomic_int64_t elapsed { 0 }; std::atomic_int64_t deleteFirstFileSize{ false }; bool isCutMerge{false}; + QList speedtimerList; }; DPFILEOPERATIONS_END_NAMESPACE