task_database_cue.c - reduce stack usage

This commit is contained in:
twinaphex 2017-09-12 05:04:27 +02:00
parent c1c42cac6b
commit c1f60c1aa6
1 changed files with 14 additions and 7 deletions

View File

@ -443,7 +443,7 @@ int find_first_data_track(const char *cue_path,
int32_t *offset, char *track_path, size_t max_len) int32_t *offset, char *track_path, size_t max_len)
{ {
int rv; int rv;
char tmp_token[MAX_TOKEN_LEN]; char * tmp_token = (char*)(MAX_TOKEN_LEN * sizeof(char));
RFILE *fd = RFILE *fd =
filestream_open(cue_path, RFILE_MODE_READ, -1); filestream_open(cue_path, RFILE_MODE_READ, -1);
@ -451,7 +451,7 @@ int find_first_data_track(const char *cue_path,
{ {
RARCH_LOG("Could not open CUE file '%s': %s\n", cue_path, RARCH_LOG("Could not open CUE file '%s': %s\n", cue_path,
strerror(errno)); strerror(errno));
return -errno; goto error;
} }
RARCH_LOG("Parsing CUE file '%s'...\n", cue_path); RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);
@ -462,15 +462,16 @@ int find_first_data_track(const char *cue_path,
{ {
if (string_is_equal(tmp_token, "FILE")) if (string_is_equal(tmp_token, "FILE"))
{ {
char cue_dir[PATH_MAX_LENGTH]; char *cue_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
cue_dir[0] = '\0'; cue_dir[0] = '\0';
fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir)); fill_pathname_basedir(cue_dir, cue_path, PATH_MAX_LENGTH * sizeof(char));
get_token(fd, tmp_token, MAX_TOKEN_LEN); get_token(fd, tmp_token, MAX_TOKEN_LEN);
fill_pathname_join(track_path, cue_dir, tmp_token, max_len); fill_pathname_join(track_path, cue_dir, tmp_token, max_len);
free(cue_dir);
} }
else if (string_is_equal(tmp_token, "TRACK")) else if (string_is_equal(tmp_token, "TRACK"))
{ {
@ -488,8 +489,7 @@ int find_first_data_track(const char *cue_path,
if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3) if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3)
{ {
RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token); RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token);
filestream_close(fd); goto error;
return -errno;
} }
*offset = ((m * 60) * (s * 75) * f) * 25; *offset = ((m * 60) * (s * 75) * f) * 25;
@ -506,6 +506,13 @@ int find_first_data_track(const char *cue_path,
rv = -EINVAL; rv = -EINVAL;
clean: clean:
free(tmp_token);
filestream_close(fd); filestream_close(fd);
return rv; return rv;
error:
free(tmp_token);
if (fd)
filestream_close(fd);
return -errno;
} }