CD-ROM Image: close log before closing the file, fixes segmentation fault on image unload.

This commit is contained in:
OBattler
2025-01-28 23:22:06 +01:00
parent 1968a36350
commit 2d7fb72830

View File

@@ -363,12 +363,9 @@ index_file_init(const uint8_t id, const char *filename, int *error, int *is_viso
static void static void
index_file_close(track_index_t *idx) index_file_close(track_index_t *idx)
{ {
if ((idx == NULL) || (idx->file == NULL) || if ((idx == NULL) || (idx->file == NULL))
(idx->file->close == NULL))
return; return;
idx->file->close(idx->file);
image_log(idx->file->log, "Log closed\n"); image_log(idx->file->log, "Log closed\n");
if (idx->file->log != NULL) { if (idx->file->log != NULL) {
@@ -376,6 +373,9 @@ index_file_close(track_index_t *idx)
idx->file->log = NULL; idx->file->log = NULL;
} }
if (idx->file->close != NULL)
idx->file->close(idx->file);
idx->file = NULL; idx->file = NULL;
} }
@@ -567,7 +567,7 @@ image_cue_get_buffer(char *str, char **line, const int up)
static int static int
image_cue_get_keyword(char **dest, char **line) image_cue_get_keyword(char **dest, char **line)
{ {
int success = image_cue_get_buffer(temp_keyword, line, 1); const int success = image_cue_get_buffer(temp_keyword, line, 1);
if (success) if (success)
*dest = temp_keyword; *dest = temp_keyword;
@@ -1905,8 +1905,8 @@ image_get_track_type(const void *local, const uint32_t sector)
const track_t *nt = &(img->tracks[i + 1]); const track_t *nt = &(img->tracks[i + 1]);
if (ct->point == 0xa0) { if (ct->point == 0xa0) {
uint8_t first = (ct->idx[1].start / 75 / 60); const uint8_t first = (ct->idx[1].start / 75 / 60);
uint8_t last = (nt->idx[1].start / 75 / 60); const uint8_t last = (nt->idx[1].start / 75 / 60);
if ((trk->point >= first) && (trk->point <= last)) { if ((trk->point >= first) && (trk->point <= last)) {
ret = (ct->idx[1].start / 75) % 60; ret = (ct->idx[1].start / 75) % 60;