add malloc check to fix

master
Glenn K. Lockwood 2019-01-23 16:02:58 -08:00 committed by Glenn K. Lockwood
parent b561f60702
commit 8996f5494f
1 changed files with 3 additions and 3 deletions

View File

@ -206,13 +206,13 @@ void parse_dirpath(char *dirpath_arg) {
} }
tmp++; tmp++;
} }
// prevent changes to the original dirpath_arg
dirpath_arg = strdup(dirpath_arg);
filenames = (char **)malloc(path_count * sizeof(char **)); filenames = (char **)malloc(path_count * sizeof(char **));
if (filenames == NULL) { if (filenames == NULL || dirpath_arg == NULL) {
FAIL("out of memory"); FAIL("out of memory");
} }
// prevent changes to the original dirpath_arg
dirpath_arg = strdup(dirpath_arg);
token = strtok(dirpath_arg, delimiter_string); token = strtok(dirpath_arg, delimiter_string);
while (token != NULL) { while (token != NULL) {
filenames[i] = token; filenames[i] = token;