mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Fix a possible leak.
Can definitely see this happening.
This commit is contained in:
parent
c259c6708e
commit
27eb38df8d
1 changed files with 11 additions and 1 deletions
|
@ -491,7 +491,13 @@ void CachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, bool readingAhead)
|
|||
backendMutex_.unlock();
|
||||
|
||||
blocksMutex_.lock();
|
||||
blocks_[cacheStartPos] = BlockInfo(buf);
|
||||
// While blocksMutex_ was unlocked, another thread may have read.
|
||||
// If so, free the one we just read.
|
||||
if (blocks_.find(cacheStartPos) == blocks_.end()) {
|
||||
blocks_[cacheStartPos] = BlockInfo(buf);
|
||||
} else {
|
||||
delete [] buf;
|
||||
}
|
||||
} else {
|
||||
blocksMutex_.unlock();
|
||||
|
||||
|
@ -502,6 +508,10 @@ void CachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, bool readingAhead)
|
|||
|
||||
blocksMutex_.lock();
|
||||
for (size_t i = 0; i < blocksToRead; ++i) {
|
||||
if (blocks_.find(cacheStartPos + i) != blocks_.end()) {
|
||||
// Written while we were busy, just skip it. Keep the existing block.
|
||||
continue;
|
||||
}
|
||||
u8 *buf = new u8[BLOCK_SIZE];
|
||||
memcpy(buf, wholeRead + (i << BLOCK_SHIFT), BLOCK_SIZE);
|
||||
blocks_[cacheStartPos + i] = BlockInfo(buf);
|
||||
|
|
Loading…
Add table
Reference in a new issue