Skip to content

Commit

Permalink
fix: [io]Memory leak due to failed asynchronous query for file inform…
Browse files Browse the repository at this point in the history
…ation

Memory leak due to failed asynchronous query for file information

Log: Memory leak due to failed asynchronous query for file information
  • Loading branch information
liyigang1 committed Aug 31, 2023
1 parent d1a2550 commit 2b85260
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
26 changes: 9 additions & 17 deletions src/dfm-base/utils/fileinfohelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,6 @@ void FileInfoHelper::cacheFileInfoByThread(const QSharedPointer<FileInfo> dfileI
});
}

void FileInfoHelper::fileRefreshAsyncCallBack(bool success, void *userData)
{
Q_UNUSED(success);
if (!userData)
return;
auto data = static_cast<FileRefreshCallBackData *>(userData);
if (!data->info)
return;

FileInfoHelper::instance().cacheFileInfoByThread(data->info);
delete data;
}

FileInfoHelper::~FileInfoHelper()
{
aboutToQuit();
Expand Down Expand Up @@ -140,8 +127,13 @@ void FileInfoHelper::handleFileRefresh(QSharedPointer<FileInfo> dfileInfo)
if (!asyncInfo)
return;

FileRefreshCallBackData *data = new FileRefreshCallBackData;
data->info = asyncInfo;
if (!asyncInfo->asyncQueryDfmFileInfo(0, &FileInfoHelper::fileRefreshAsyncCallBack, data))
delete data;
auto callback = [asyncInfo](bool success, void *data){
Q_UNUSED(data);
if (!success) {
qWarning() << "Failed to query file information asynchronously! url = " << asyncInfo->fileUrl();
return ;
}
FileInfoHelper::instance().cacheFileInfoByThread(asyncInfo);
};
asyncInfo->asyncQueryDfmFileInfo(0, callback);
}
6 changes: 0 additions & 6 deletions src/dfm-base/utils/fileinfohelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ namespace dfmbase {
class FileInfoHelper : public QObject
{
Q_OBJECT
public:
struct FileRefreshCallBackData{
FileInfoPointer info{ nullptr };
};

public:
~FileInfoHelper() override;
static FileInfoHelper &instance();
Expand All @@ -36,7 +31,6 @@ class FileInfoHelper : public QObject
const QString &inod, const bool isGvfs);
void fileRefreshAsync(const QSharedPointer<dfmbase::FileInfo> dfileInfo);
void cacheFileInfoByThread(const QSharedPointer<FileInfo> dfileInfo);
static void fileRefreshAsyncCallBack(bool success, void *userData);

private:
explicit FileInfoHelper(QObject *parent = nullptr);
Expand Down

0 comments on commit 2b85260

Please sign in to comment.