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,7 +97,8 @@ rom_check(const char *fn)
else {
fp = fopen(fn, "rb");
ret = (fp != NULL);
fclose(fp);
if (fp != NULL)
fclose(fp);
}
return ret;
@@ -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,7 +328,8 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t
}
}
(void) fclose(fp);
if (fp != NULL)
(void) fclose(fp);
return 1;
}
@@ -353,7 +358,8 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
fatal("rom_load_linear(): Error reading data\n");
}
(void) fclose(fp);
if (fp != NULL)
(void) fclose(fp);
return 1;
}
@@ -397,7 +403,8 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t
}
}
(void) fclose(fp);
if (fp != NULL)
(void) fclose(fp);
return 1;
}
@@ -438,8 +445,10 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
}
}
(void) fclose(fph);
(void) fclose(fpl);
if (fph != NULL)
(void) fclose(fph);
if (fpl != NULL)
(void) fclose(fpl);
return 1;
}