From 620f541ca188784173552513d22522c7f7fd385e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 5 Jun 2016 18:32:26 +0200 Subject: [PATCH] detect_ps1_game_sub - fix 'resource leak' --- tasks/task_database_cue.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 85da556266..04b5c8c6e1 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -181,10 +181,7 @@ static int detect_ps1_game_sub(const char *track_path, while (tmp < (buffer + 2048 * 2)) { if (!*tmp) - { - filestream_close(fp); - return 0; - } + goto error; if (!strncasecmp((const char*)(tmp + 33), "SYSTEM.CNF;1", 12)) break; @@ -193,10 +190,7 @@ static int detect_ps1_game_sub(const char *track_path, } if(tmp >= (buffer + 2048 * 2)) - { - filestream_close(fp); - return 0; - } + goto error; cd_sector = tmp[2] | (tmp[3] << 8) | (tmp[4] << 16); filestream_seek(fp, skip + cd_sector * frame_size, SEEK_SET); @@ -208,7 +202,7 @@ static int detect_ps1_game_sub(const char *track_path, tmp++; if(!*tmp) - return 0; + goto error; boot_file = tmp; while(*tmp && *tmp != '\n') @@ -240,6 +234,10 @@ static int detect_ps1_game_sub(const char *track_path, filestream_close(fp); return 1; + +error: + filestream_close(fp); + return 0; } int detect_ps1_game(const char *track_path, char *game_id) @@ -368,6 +366,7 @@ int detect_system(const char *track_path, int32_t offset, RARCH_LOG("Could not find compatible system\n"); rv = -EINVAL; + clean: filestream_close(fd); return rv;