GB, GBA Savedata: Fix memory leaks when loading new saves

This commit is contained in:
Vicki Pfau 2022-05-13 00:04:16 -07:00
parent aad85a7950
commit 8f5e755c09
3 changed files with 8 additions and 0 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;