diff options
| author | Akseli Lahtinen <[email protected]> | 2025-06-05 11:49:22 +0300 |
|---|---|---|
| committer | Akseli Lahtinen <[email protected]> | 2025-06-09 15:55:49 +0300 |
| commit | 04e493d78cdf46e64562fe8a302426b1fd8c47df (patch) | |
| tree | 3263dafd1348f00f00398275b519400da0d7c30a | |
| parent | 697d58e9727e229abb81956d27a05d1f02d8c775 (diff) | |
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
| -rw-r--r-- | src/views/viewproperties.cpp | 25 |
1 files 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<QTemporaryFile> 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()); |
