Fix memory leak in QFileInfo::exists()

Use the the legacy file engine object created in static function
QFileInfo::exists() as the engine of the QFileInfo object to prevent
memory leak. This can also boost a little performance.

Change-Id: I06317d158d487be5ef15fe3244a917a371563ac9
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
bb10
Jian Liang 2013-10-10 14:28:22 +08:00 committed by The Qt Project
parent 54b0e94cfb
commit 5c87044870
2 changed files with 16 additions and 1 deletions

View File

@ -691,7 +691,8 @@ bool QFileInfo::exists(const QString &file)
QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data);
// Expensive fallback to non-QFileSystemEngine implementation
if (engine)
return QFileInfo(file).exists();
return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
return data.exists();
}

View File

@ -120,6 +120,20 @@ public:
metaData = QFileSystemMetaData();
}
inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, QAbstractFileEngine *engine)
: fileEntry(file),
metaData(data),
fileEngine(engine),
cachedFlags(0),
#ifndef QT_NO_FSFILEENGINE
isDefaultConstructed(false),
#else
isDefaultConstructed(!fileEngine),
#endif
cache_enabled(true), fileFlags(0), fileSize(0)
{
}
inline void clearFlags() const {
fileFlags = 0;
cachedFlags = 0;