mirror of https://github.com/mgba-emu/mgba.git
GB, GBA Savedata: Fix memory leaks when loading new saves
This commit is contained in:
parent
aad85a7950
commit
8f5e755c09
|
@ -229,6 +229,9 @@ static void GBSramDeinit(struct GB* gb) {
|
|||
bool GBLoadSave(struct GB* gb, struct VFile* vf) {
|
||||
GBSramDeinit(gb);
|
||||
gb->sramVf = vf;
|
||||
if (gb->sramRealVf && gb->sramRealVf != vf) {
|
||||
gb->sramRealVf->close(gb->sramRealVf);
|
||||
}
|
||||
gb->sramRealVf = vf;
|
||||
if (gb->sramSize) {
|
||||
GBResizeSram(gb, gb->sramSize);
|
||||
|
|
|
@ -75,6 +75,8 @@ static void GBAInit(void* cpu, struct mCPUComponent* component) {
|
|||
GBAMemoryInit(gba);
|
||||
|
||||
gba->memory.savedata.timing = &gba->timing;
|
||||
gba->memory.savedata.vf = NULL;
|
||||
gba->memory.savedata.realVf = NULL;
|
||||
GBASavedataInit(&gba->memory.savedata, NULL);
|
||||
|
||||
gba->video.p = gba;
|
||||
|
|
|
@ -45,6 +45,9 @@ void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) {
|
|||
savedata->command = EEPROM_COMMAND_NULL;
|
||||
savedata->flashState = FLASH_STATE_RAW;
|
||||
savedata->vf = vf;
|
||||
if (savedata->realVf && savedata->realVf != vf) {
|
||||
savedata->realVf->close(savedata->realVf);
|
||||
}
|
||||
savedata->realVf = vf;
|
||||
savedata->mapMode = MAP_WRITE;
|
||||
savedata->maskWriteback = false;
|
||||
|
|
Loading…
Reference in New Issue