From c2de079a9d08982c2d8a66b7f6105b8ae3e05094 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 22 Mar 2021 23:48:19 -0700 Subject: [PATCH] GB: Properly unmap ROM base when unloading ROM --- src/gb/gb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gb/gb.c b/src/gb/gb.c index 79d309cf6..404c660c3 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -293,6 +293,10 @@ void GBSavedataUnmask(struct GB* gb) { void GBUnloadROM(struct GB* gb) { // TODO: Share with GBAUnloadROM + off_t romBase = gb->memory.romBase - gb->memory.rom; + if (romBase >= 0 && ((size_t) romBase < gb->memory.romSize || (size_t) romBase < gb->yankedRomSize)) { + gb->memory.romBase = NULL; + } if (gb->memory.rom && !gb->isPristine) { if (gb->yankedRomSize) { gb->yankedRomSize = 0;