mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
tokenize: free content of argv on failure, and reset the argv pointer
This fixes a memory leak when we failed to parse a command line (for example, because it contained an unclosed quote).
This commit is contained in:
parent
ba851c963e
commit
e225be1c50
1 changed files with 4 additions and 3 deletions
|
|
@ -49,9 +49,7 @@ tokenize_cmdline(const char *cmdline, char ***argv)
|
|||
if (end == NULL) {
|
||||
if (delim != ' ') {
|
||||
LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single");
|
||||
free(*argv);
|
||||
*argv = NULL;
|
||||
return false;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!push_argv(argv, &argv_size, p, final_end - p, &idx) ||
|
||||
|
|
@ -97,6 +95,9 @@ tokenize_cmdline(const char *cmdline, char ***argv)
|
|||
return true;
|
||||
|
||||
err:
|
||||
for (size_t i = 0; i < idx; i++)
|
||||
free((*argv)[i]);
|
||||
free(*argv);
|
||||
*argv = NULL;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue