summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
697d58e)
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
return new ViewPropertySettings(KSharedConfig::openConfig(settingsFile, KConfig::SimpleConfig));
}
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
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());
QFile::remove(tempFile->fileName());
QFile::copy(settingsFile, tempFile->fileName());
return nullptr;
}
// load view properties from xattr to temp file then loads into ViewPropertySettings
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());
QFile outputFile(tempFile->fileName());
outputFile.open(QIODevice::WriteOnly);
outputFile.write(viewPropertiesString.toUtf8());