diff --git a/src/dfm-io/dfm-io/denumerator.cpp b/src/dfm-io/dfm-io/denumerator.cpp index 03091610..17f633d6 100644 --- a/src/dfm-io/dfm-io/denumerator.cpp +++ b/src/dfm-io/dfm-io/denumerator.cpp @@ -302,7 +302,7 @@ bool DEnumeratorPrivate::checkNameFilter(const QString &fileName) bool DEnumeratorPrivate::openDirByfts() { char *paths[2] = { nullptr, nullptr }; - paths[0] = filePath(uri); + paths[0] = strdup(filePath(uri).constData()); if (!paths[0]) { error.setCode(DFMIOErrorCode::DFM_IO_ERROR_FAILED); return false; @@ -433,15 +433,15 @@ void DEnumeratorPrivate::setQueryAttributes(const QString &attributes) queryAttributes = attributes; } -char *DEnumeratorPrivate::filePath(const QUrl &url) +QByteArray DEnumeratorPrivate::filePath(const QUrl &url) { if (url.userInfo().startsWith("originPath::")) - return strdup(url.userInfo().replace("originPath::", "").toLatin1().constData()); + return url.userInfo().replace("originPath::", "").toLatin1(); QString path = url.path(); if (path != "/" && path.endsWith("/")) path = path.left(path.length() - 1); - return strdup(path.toUtf8().constData()); + return path.toUtf8(); } QUrl DEnumeratorPrivate::buildUrl(const QUrl &url, const char *fileName) @@ -831,11 +831,8 @@ QList> DEnumerator::sortFileInfoList() QSet hideList; QUrl urlHidden = d->buildUrl(d->uri, ".hidden"); hideList = DLocalHelper::hideListFromUrl(urlHidden); - char *dirPath = d->filePath(d->uri); - if (!dirPath) { - qWarning() << "Failed to get file path for uri:" << d->uri; - return {}; - } + QByteArray dirPathBa = d->filePath(d->uri); + const char *dirPath = dirPathBa.constData(); while (1) { FTSENT *ent = fts_read(d->fts); @@ -857,8 +854,6 @@ QList> DEnumerator::sortFileInfoList() fts_close(d->fts); d->fts = nullptr; - // Clean up allocated memory - free(dirPath); if (d->isMixDirAndFile) return listFile; diff --git a/src/dfm-io/dfm-io/private/denumerator_p.h b/src/dfm-io/dfm-io/private/denumerator_p.h index d8b5efd0..4a8c8295 100644 --- a/src/dfm-io/dfm-io/private/denumerator_p.h +++ b/src/dfm-io/dfm-io/private/denumerator_p.h @@ -55,7 +55,7 @@ class DEnumeratorPrivate : public QObject, public QEnableSharedFromThis> fileInfoList(); void setQueryAttributes(const QString &attributes); - char *filePath(const QUrl &url); + QByteArray filePath(const QUrl &url); QUrl buildUrl(const QUrl &url, const char *fileName); static void enumUriAsyncCallBack(GObject *sourceObject,