DS: Fix leaking BIOS and firmware filehandles

This commit is contained in:
Vicki Pfau 2020-07-20 09:06:06 -07:00
parent 0b0739f567
commit 39df2d1a5c
2 changed files with 35 additions and 0 deletions

View File

@ -15,6 +15,7 @@ Bugfixes:
- GBA Video: Fix mode 2 out-of-bounds VRAM crash
- GBA Video: Fix regression adjusting brightness of backdrop
- DS GX: Properly reject invalid commands
- DS: Fix leaking BIOS and firmware filehandles
Misc:
- DS GX: Clean up and unify texture mapping
- DS Core: Add symbol loading

View File

@ -238,6 +238,25 @@ void DSUnloadROM(struct DS* ds) {
}
void DSDestroy(struct DS* ds) {
if (ds->bios7Vf) {
ds->bios7Vf->unmap(ds->bios7Vf, ds->memory.bios7, DS7_SIZE_BIOS);
ds->bios7Vf->close(ds->bios7Vf);
ds->bios7Vf = NULL;
}
if (ds->bios9Vf) {
if (ds->bios9Vf->size(ds->bios9Vf) == 0x1000) {
free(ds->memory.bios9);
} else {
ds->bios9Vf->unmap(ds->bios9Vf, ds->memory.bios9, DS9_SIZE_BIOS);
}
ds->bios9Vf->close(ds->bios9Vf);
ds->bios9Vf = NULL;
}
if (ds->firmwareVf) {
ds->firmwareVf->close(ds->firmwareVf);
ds->firmwareVf = NULL;
}
CircleBufferDeinit(&ds->ds7.fifo);
CircleBufferDeinit(&ds->ds9.fifo);
DSUnloadROM(ds);
@ -557,10 +576,22 @@ bool DSLoadBIOS(struct DS* ds, struct VFile* vf) {
}
crc = doCrc32(data, size);
if (crc == DS7_BIOS_CHECKSUM) {
if (ds->bios7Vf) {
ds->bios7Vf->unmap(ds->bios7Vf, ds->memory.bios7, DS7_SIZE_BIOS);
ds->bios7Vf->close(ds->bios7Vf);
}
ds->bios7Vf = vf;
ds->memory.bios7 = data;
mLOG(DS, INFO, "Official DS ARM7 BIOS detected");
} else if (crc == DS9_BIOS_CHECKSUM) {
if (ds->bios9Vf) {
if (ds->bios9Vf->size(ds->bios9Vf) == 0x1000) {
free(ds->memory.bios9);
} else {
ds->bios9Vf->unmap(ds->bios9Vf, ds->memory.bios9, DS9_SIZE_BIOS);
}
ds->bios9Vf->close(ds->bios9Vf);
}
ds->bios9Vf = vf;
ds->memory.bios9 = data;
mLOG(DS, INFO, "Official DS ARM9 BIOS detected");
@ -581,6 +612,9 @@ bool DSLoadFirmware(struct DS* ds, struct VFile* vf) {
return false;
}
mLOG(DS, INFO, "Found DS firmware");
if (ds->firmwareVf) {
ds->firmwareVf->close(ds->firmwareVf);
}
ds->firmwareVf = vf;
return true;
}