diff --git a/CHANGES b/CHANGES index bc87a732b..2b923ba6a 100644 --- a/CHANGES +++ b/CHANGES @@ -65,6 +65,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 f4ac50fe9..84ad8007e 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); @@ -733,14 +737,14 @@ void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) { void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) { struct GBA* gba = (struct GBA*) cpu->master; + if (cpu->executionMode == MODE_THUMB && (opcode & 0xFFC0) == 0xE800) { + mLOG(GBA, INFO, "Hit Wii U VC opcode: %08x", opcode); + return; + } if (!gba->yankedRomSize) { // TODO: More sensible category? mLOG(GBA, WARN, "Illegal opcode: %08x", opcode); } - if (cpu->executionMode == MODE_THUMB && (opcode & 0xFFC0) == 0xE800) { - mLOG(GBA, DEBUG, "Hit Wii U VC opcode: %08x", opcode); - return; - } #ifdef USE_DEBUGGERS if (gba->debugger) { struct mDebuggerEntryInfo info = { diff --git a/src/platform/posix/memory.c b/src/platform/posix/memory.c index 7892a5985..67cdd96d7 100644 --- a/src/platform/posix/memory.c +++ b/src/platform/posix/memory.c @@ -5,6 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#ifndef DISABLE_ANON_MMAP +#ifdef __SANITIZE_ADDRESS__ +#define DISABLE_ANON_MMAP +#elif defined(__has_feature) +#if __has_feature(address_sanitizer) +#define DISABLE_ANON_MMAP +#endif +#endif +#endif + +#ifndef DISABLE_ANON_MMAP #include void* anonymousMemoryMap(size_t size) { @@ -14,3 +25,13 @@ void* anonymousMemoryMap(size_t size) { void mappedMemoryFree(void* memory, size_t size) { munmap(memory, size); } +#else +void* anonymousMemoryMap(size_t size) { + return calloc(1, size); +} + +void mappedMemoryFree(void* memory, size_t size) { + UNUSED(size); + free(memory); +} +#endif