From c14385191693d8ff589a6f432960cdd437cf150b Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 8 Oct 2024 04:39:53 -0700 Subject: [PATCH] Core: Fix patch autoloading leaking the file handle --- CHANGES | 1 + src/core/core.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 3159e66e9..da116a015 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Emulation fixes: - GBA Serialize: Properly restore GPIO register state (fixes mgba.io/i/3294) - GBA SIO: Fix MULTI mode SIOCNT bit 7 writes on secondary GBAs (fixes mgba.io/i/3110) Other fixes: + - Core: Fix patch autoloading leaking the file handle - GB: Fix uninitialized save data when loading undersized temporary saves - GB, GBA Core: Fix memory leak if reloading debug symbols - GB Serialize: Prevent loading invalid states where LY >= 144 in modes other than 1 diff --git a/src/core/core.c b/src/core/core.c index 6a64da670..47e15eb1b 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -237,9 +237,22 @@ bool mCoreAutoloadPatch(struct mCore* core) { if (!core->dirs.patch) { return false; } - return core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ups", O_RDONLY)) || - core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ips", O_RDONLY)) || - core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".bps", O_RDONLY)); + struct VFile* vf = NULL; + if (!vf) { + vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".bps", O_RDONLY); + } + if (!vf) { + vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ups", O_RDONLY); + } + if (!vf) { + vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ips", O_RDONLY); + } + if (!vf) { + return false; + } + bool result = core->loadPatch(core, vf); + vf->close(vf); + return result; } bool mCoreAutoloadCheats(struct mCore* core) {