From 19c16081c6bd374cf50e28b43332115707ce917d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Wed, 17 Nov 2021 14:21:27 +0100 Subject: [PATCH] load: don't leak file handles; don't ignore read errors --- src/uxnemu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uxnemu.c b/src/uxnemu.c index b56b975..fa9b86e 100644 --- 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;