From cf7c827d0d5b3eae78aea19dca54ed252a05945e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:03:44 +0200 Subject: [PATCH] Fix possible null dereference and resource leak --- src/title.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/title.c b/src/title.c index dd1874f8dc..f4d0d6de75 100644 --- a/src/title.c +++ b/src/title.c @@ -579,11 +579,11 @@ static uint8 *title_script_load() sprintf(path, "%s%c%s", gExePath, platform_get_path_separator(), filePath); log_verbose("loading title script, %s", path); file = SDL_RWFromFile(path, "r"); - sint64 fileSize = SDL_RWsize(file); if (file == NULL) { log_error("unable to load title script"); return NULL; } + sint64 fileSize = SDL_RWsize(file); uint8 *binaryScript = (uint8*)malloc(1024 * 8); if (binaryScript == NULL) { @@ -624,7 +624,8 @@ static uint8 *title_script_load() *scriptPtr++ = atoi(part1) & 0xFF; } else { log_error("unknown token, %s", token); - free(binaryScript); + SafeFree(binaryScript); + SDL_RWclose(file); return NULL; } }