mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-25 13:17:46 +00:00
common: Fix use-after-free bug with QLatin1String in FileCache
This commit is contained in:
parent
f8d7d04e78
commit
62d5e0b1b9
2 changed files with 10 additions and 8 deletions
|
@ -16,12 +16,12 @@ class FileCache
|
||||||
public:
|
public:
|
||||||
explicit FileCache(GameData &data);
|
explicit FileCache(GameData &data);
|
||||||
|
|
||||||
bool fileExists(const QLatin1String &path);
|
bool fileExists(const QString &path);
|
||||||
physis_Buffer &lookupFile(const QLatin1String &path);
|
physis_Buffer &lookupFile(const QString &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QLatin1String, physis_Buffer> cachedBuffers;
|
QMap<QString, physis_Buffer> cachedBuffers;
|
||||||
QHash<QLatin1String, bool> cachedExist;
|
QHash<QString, bool> cachedExist;
|
||||||
GameData &data;
|
GameData &data;
|
||||||
QMutex bufferMutex, existMutex;
|
QMutex bufferMutex, existMutex;
|
||||||
};
|
};
|
|
@ -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);
|
QMutexLocker locker(&bufferMutex);
|
||||||
|
|
||||||
if (!cachedBuffers.contains(path)) {
|
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];
|
return cachedBuffers[path];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileCache::fileExists(const QLatin1String &path)
|
bool FileCache::fileExists(const QString &path)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&existMutex);
|
QMutexLocker locker(&existMutex);
|
||||||
|
|
||||||
if (!cachedExist.contains(path)) {
|
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];
|
return cachedExist[path];
|
||||||
|
|
Loading…
Add table
Reference in a new issue