Savestate: Fix file handle reuse and leaks when reopening files

DirectoryFileSystem reused one entry across files, so a failed reopen
could seek another file's handle. VirtualDiscFileSystem leaked every open
handle on each load. MemoryStick ignored the saved free space basis.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-28 09:34:06 -06:00
1 parent a4e169893f
commit d6c74156b1
3 files changed
+30 -8

No files matched your search

@@ -206,6 +206,11 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p)
if (p.mode == p.MODE_READ)
{
for (auto &[_, entry] : entries) {
if (entry.type != VFILETYPE_ISO) {
entry.Close();
}
}
entries.clear();
for (int i = 0; i < entryCount; i++)
@@ -222,6 +227,11 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p)
// open file
if (of.type != VFILETYPE_ISO) {
if (of.fileIndex >= fileList.size()) {
ERROR_LOG(Log::FileSystem, "Savestate has an invalid file index %u", of.fileIndex);
p.SetError(p.ERROR_FAILURE);
return;
}
if (fileList[of.fileIndex].handler != NULL) {
of.handler = fileList[of.fileIndex].handler;
}