diff --git a/CHANGES b/CHANGES index 5fb6b4d01..4255015f2 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Other fixes: - All: Correct more format strings on Windows (fixes mgba.io/i/1817) - CMake: Fix build with libzip 1.7 - GB Core: Fix extracting SRAM when none is present + - GBA: Fix leak if attempting to load BIOS multiple times - GBA Savedata: Fix extracting save when not yet configured in-game - Qt: Fix file handle leak on opening an invalid ROM - Qt: Fix Italian RTC translation (fixes mgba.io/i/1798) diff --git a/src/gba/gba.c b/src/gba/gba.c index 43fe7cc26..d5608cdab 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -444,7 +444,6 @@ void GBAYankROM(struct GBA* gba) { } void GBALoadBIOS(struct GBA* gba, struct VFile* vf) { - gba->biosVf = vf; if (vf->size(vf) != SIZE_BIOS) { mLOG(GBA, WARN, "Incorrect BIOS size"); return; @@ -454,6 +453,11 @@ void GBALoadBIOS(struct GBA* gba, struct VFile* vf) { mLOG(GBA, WARN, "Couldn't map BIOS"); return; } + if (gba->biosVf) { + gba->biosVf->unmap(gba->biosVf, gba->memory.bios, SIZE_BIOS); + gba->biosVf->close(gba->biosVf); + } + gba->biosVf = vf; gba->memory.bios = bios; gba->memory.fullBios = 1; uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);