mirror of https://github.com/mgba-emu/mgba.git
GB: Fix potential double-free of non-pristine ROM memory
This commit is contained in:
parent
e3983d3330
commit
064d6ce183
|
@ -405,7 +405,9 @@ void GBUnloadROM(struct GB* gb) {
|
|||
|
||||
if (gb->romVf) {
|
||||
#ifndef FIXED_ROM_BUFFER
|
||||
gb->romVf->unmap(gb->romVf, gb->memory.rom, gb->pristineRomSize);
|
||||
if (gb->isPristine && gb->memory.rom) {
|
||||
gb->romVf->unmap(gb->romVf, gb->memory.rom, gb->pristineRomSize);
|
||||
}
|
||||
#endif
|
||||
gb->romVf->close(gb->romVf);
|
||||
gb->romVf = NULL;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <mgba/internal/sm83/sm83.h>
|
||||
|
||||
#include <mgba-util/memory.h>
|
||||
#include <mgba-util/vfs.h>
|
||||
|
||||
mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory", "gb.memory");
|
||||
|
||||
|
@ -1006,6 +1007,11 @@ void _pristineCow(struct GB* gb) {
|
|||
if (gb->memory.rom == gb->memory.romBase) {
|
||||
gb->memory.romBase = newRom;
|
||||
}
|
||||
if (gb->romVf) {
|
||||
gb->romVf->unmap(gb->romVf, gb->memory.rom, gb->memory.romSize);
|
||||
gb->romVf->close(gb->romVf);
|
||||
gb->romVf = NULL;
|
||||
}
|
||||
gb->memory.rom = newRom;
|
||||
GBMBCSwitchBank(gb, gb->memory.currentBank);
|
||||
gb->isPristine = false;
|
||||
|
|
Loading…
Reference in New Issue