]> cloud.milkyroute.net Git - dolphin.git/commitdiff
viewproperties: Fix leaking file descriptors
authorAkseli Lahtinen <akselmo@akselmo.dev>
Thu, 5 Jun 2025 08:49:22 +0000 (11:49 +0300)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Mon, 9 Jun 2025 12:55:49 +0000 (15:55 +0300)
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

index 8e09009e58a2fa8ab9860ef1d9353bc3e19055f0..8bf3b2531290a68d8be66928e310ada3820e5575 100644 (file)
@@ -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());