Skip to content

Commit

Permalink
fix: dde-file-manager copy crash,prevent memory leak in speed timer h…
Browse files Browse the repository at this point in the history
…andling

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
  • Loading branch information
liyigang1 committed Nov 13, 2024
1 parent 89849af commit bbc750f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void AbstractWorker::pause()
return;
if (speedtimer) {
elapsed += speedtimer->elapsed();
delete speedtimer;
speedtimerList.append(speedtimer);
speedtimer = nullptr;
JobInfoPointer info(new QMap<quint8, QVariant>);
info->insert(AbstractJobHandler::NotifyInfoKey::kJobtypeKey, QVariant::fromValue(jobType));
Expand Down Expand Up @@ -667,6 +667,8 @@ AbstractWorker::~AbstractWorker()
delete speedtimer;
speedtimer = nullptr;
}

qDeleteAll(speedtimerList);
}

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ protected slots:
std::atomic_int64_t elapsed { 0 };
std::atomic_int64_t deleteFirstFileSize{ false };
bool isCutMerge{false};
QList<QElapsedTimer *> speedtimerList;
};
DPFILEOPERATIONS_END_NAMESPACE

Expand Down

0 comments on commit bbc750f

Please sign in to comment.