From 04e493d78cdf46e64562fe8a302426b1fd8c47df Mon Sep 17 00:00:00 2001 From: Akseli Lahtinen Date: Thu, 5 Jun 2025 11:49:22 +0300 Subject: [PATCH] viewproperties: Fix leaking file descriptors File descriptors would keep leaking here since tempFile never gets deleted. This would be especially noticeable when browsing /tmp/ folder. This patch makes the QTemporaryFile an unique_ptr, so it gets deleted when it's out of scope. This also causes the files to be handled accordingly. BUG: 505215 --- src/views/viewproperties.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index 8e09009e5..8bf3b2531 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -42,22 +42,14 @@ ViewPropertySettings *ViewProperties::loadProperties(const QString &folderPath) return new ViewPropertySettings(KSharedConfig::openConfig(settingsFile, KConfig::SimpleConfig)); } - auto createTempFile = []() -> QTemporaryFile * { - QTemporaryFile *tempFile = new QTemporaryFile; - tempFile->setAutoRemove(false); - if (!tempFile->open()) { - qCWarning(DolphinDebug) << "Could not open temp file"; - return nullptr; - } - return tempFile; - }; - + std::unique_ptr tempFile(new QTemporaryFile()); + tempFile->setAutoRemove(false); + if (!tempFile->open()) { + qCWarning(DolphinDebug) << "Could not open temp file"; + return nullptr; + } if (QFile::exists(settingsFile)) { // copy settings to tempfile to load them separately - const QTemporaryFile *tempFile = createTempFile(); - if (!tempFile) { - return nullptr; - } QFile::remove(tempFile->fileName()); QFile::copy(settingsFile, tempFile->fileName()); @@ -84,11 +76,6 @@ ViewPropertySettings *ViewProperties::loadProperties(const QString &folderPath) return nullptr; } // load view properties from xattr to temp file then loads into ViewPropertySettings - // clear the temp file - const QTemporaryFile *tempFile = createTempFile(); - if (!tempFile) { - return nullptr; - } QFile outputFile(tempFile->fileName()); outputFile.open(QIODevice::WriteOnly); outputFile.write(viewPropertiesString.toUtf8()); -- 2.47.3