1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-25 05:17:44 +00:00

common: Fix use-after-free bug with QLatin1String in FileCache

This commit is contained in:
Joshua Goins 2023-10-13 15:01:23 -04:00
parent f8d7d04e78
commit 62d5e0b1b9
2 changed files with 10 additions and 8 deletions

View file

@ -16,12 +16,12 @@ class FileCache
public:
explicit FileCache(GameData &data);
bool fileExists(const QLatin1String &path);
physis_Buffer &lookupFile(const QLatin1String &path);
bool fileExists(const QString &path);
physis_Buffer &lookupFile(const QString &path);
private:
QMap<QLatin1String, physis_Buffer> cachedBuffers;
QHash<QLatin1String, bool> cachedExist;
QMap<QString, physis_Buffer> cachedBuffers;
QHash<QString, bool> cachedExist;
GameData &data;
QMutex bufferMutex, existMutex;
};

View file

@ -10,23 +10,25 @@ FileCache::FileCache(GameData &data)
{
}
physis_Buffer &FileCache::lookupFile(const QLatin1String &path)
physis_Buffer &FileCache::lookupFile(const QString &path)
{
QMutexLocker locker(&bufferMutex);
if (!cachedBuffers.contains(path)) {
cachedBuffers[path] = physis_gamedata_extract_file(&data, path.data());
std::string pathstd = path.toStdString();
cachedBuffers[path] = physis_gamedata_extract_file(&data, pathstd.c_str());
}
return cachedBuffers[path];
}
bool FileCache::fileExists(const QLatin1String &path)
bool FileCache::fileExists(const QString &path)
{
QMutexLocker locker(&existMutex);
if (!cachedExist.contains(path)) {
cachedExist[path] = physis_gamedata_exists(&data, path.data());
std::string pathstd = path.toStdString();
cachedExist[path] = physis_gamedata_exists(&data, pathstd.c_str());
}
return cachedExist[path];