Segfault fixes in rom.c

This commit is contained in:
Jasmine Iwanek
2025-05-06 00:59:56 -04:00
parent c992a44b44
commit dee023dc1c

View File

@@ -97,6 +97,7 @@ rom_check(const char *fn)
else {
fp = fopen(fn, "rb");
ret = (fp != NULL);
if (fp != NULL)
fclose(fp);
}
@@ -134,6 +135,9 @@ rom_fopen(const char *fn, char *mode)
char temp[1024];
FILE *fp = NULL;
if ((fn == NULL) || (mode == NULL))
return NULL;
if (strstr(fn, "roms/") == fn) {
/* Relative path */
for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
@@ -324,6 +328,7 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t
}
}
if (fp != NULL)
(void) fclose(fp);
return 1;
@@ -353,6 +358,7 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
fatal("rom_load_linear(): Error reading data\n");
}
if (fp != NULL)
(void) fclose(fp);
return 1;
@@ -397,6 +403,7 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t
}
}
if (fp != NULL)
(void) fclose(fp);
return 1;
@@ -438,7 +445,9 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
}
}
if (fph != NULL)
(void) fclose(fph);
if (fpl != NULL)
(void) fclose(fpl);
return 1;