From d708a1025d7b8246ae531828728114dad327e1ce Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 28 Aug 2016 01:44:27 -0700 Subject: [PATCH] GBA: Fix filehandle leak with savegames --- CHANGES | 1 + src/gba/memory.c | 4 ++++ src/gba/savedata.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index 770ac73e5..fc7321d9b 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,7 @@ Bugfixes: - VFS: Fix uninitialized varaible reading from 7z - GBA: Fix losing IRQs when CPSR I bit isn't cleared - VFS: Fix reading multiple files from a 7z archive + - GBA: Fix filehandle leak with savegames Misc: - 3DS: Use blip_add_delta_fast for a small speed improvement - OpenGL: Log shader compilation failure diff --git a/src/gba/memory.c b/src/gba/memory.c index 127df6da2..7b14cb4ec 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -12,6 +12,7 @@ #include "gba/hle-bios.h" #include "util/math.h" #include "util/memory.h" +#include "util/vfs.h" #define IDLE_LOOP_THRESHOLD 10000 @@ -92,6 +93,9 @@ void GBAMemoryDeinit(struct GBA* gba) { mappedMemoryFree(gba->memory.rom, gba->memory.romSize); } GBASavedataDeinit(&gba->memory.savedata); + if (gba->memory.savedata.realVf) { + gba->memory.savedata.realVf->close(gba->memory.savedata.realVf); + } } void GBAMemoryReset(struct GBA* gba) { diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 6dd6e9dda..0d9724915 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -47,6 +47,9 @@ void GBASavedataDeinit(struct GBASavedata* savedata) { if (savedata->vf) { size_t size = GBASavedataSize(savedata); savedata->vf->unmap(savedata->vf, savedata->data, size); + if (savedata->vf != savedata->realVf) { + savedata->vf->close(savedata->vf); + } savedata->vf = 0; } else { switch (savedata->type) {