From 39203a0dafcb93542227e86b86229d7ad7ac7f00 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 20 Jul 2020 09:19:46 -0700 Subject: [PATCH] GBA: Fix leak if attempting to load BIOS multiple times --- CHANGES | 1 + src/gba/gba.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 7b5b62412..e249da41e 100644 --- a/CHANGES +++ b/CHANGES @@ -39,6 +39,7 @@ Other fixes: - FFmpeg: Fix some small memory leaks - FFmpeg: Fix encoding of time base - 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: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) - Qt: Fix static compilation in MinGW (fixes mgba.io/i/1769) diff --git a/src/gba/gba.c b/src/gba/gba.c index d33c7510a..a1512c1f0 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -443,7 +443,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; @@ -453,6 +452,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);