uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 19c16081c6bd374cf50e28b43332115707ce917d
parent 6c1720e328d2ed6d5e9ac0a6a84f57ac2d360d84
Author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date:   Wed, 17 Nov 2021 14:21:27 +0100

load: don't leak file handles; don't ignore read errors

Diffstat:
Msrc/uxnemu.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -422,8 +422,11 @@ static int load(Uxn *u, char *rom) { FILE *f; + int r; if(!(f = fopen(rom, "rb"))) return 0; - fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); + r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f); + fclose(f); + if(r < 1) return 0; fprintf(stderr, "Loaded %s\n", rom); SDL_SetWindowTitle(gWindow, rom); return 1;