From: Todd C. Miller Date: Fri, 29 Jan 2016 18:34:09 +0000 (-0700) Subject: Plug some memory leaks in the tests. X-Git-Tag: SUDO_1_8_16^2~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=73163c750a3030b68eabe0de6387da08d964ad2a;p=sudo Plug some memory leaks in the tests. --- diff --git a/plugins/sudoers/regress/iolog_path/check_iolog_path.c b/plugins/sudoers/regress/iolog_path/check_iolog_path.c index dd06d4c84..fd3a5188f 100644 --- a/plugins/sudoers/regress/iolog_path/check_iolog_path.c +++ b/plugins/sudoers/regress/iolog_path/check_iolog_path.c @@ -80,6 +80,7 @@ do_check(char *dir_in, char *file_in, char *tdir_out, char *tfile_out) sudo_warnx("%s: expected %s, got %s", file_in, file_out, slash + 1); error = 1; } + free(path); return error; } @@ -158,21 +159,33 @@ main(int argc, char *argv[]) sudo_fatalx("group ID %s: %s", line, errstr); break; case 5: + if (user_shost != NULL) + free(user_shost); user_shost = strdup(line); break; case 6: + if (user_base != NULL) + free(user_base); user_base = strdup(line); break; case 7: + if (dir_in != NULL) + free(dir_in); dir_in = strdup(line); break; case 8: + if (file_in != NULL) + free(file_in); file_in = strdup(line); break; case 9: + if (dir_out != NULL) + free(dir_out); dir_out = strdup(line); break; case 10: + if (file_out != NULL) + free(file_out); file_out = strdup(line); break; case 11: diff --git a/plugins/sudoers/regress/parser/check_fill.c b/plugins/sudoers/regress/parser/check_fill.c index 85dce0faf..8d59e5538 100644 --- a/plugins/sudoers/regress/parser/check_fill.c +++ b/plugins/sudoers/regress/parser/check_fill.c @@ -99,6 +99,10 @@ static struct fill_test args_data[] = { static int check_fill(const char *input, int len, int addspace, const char *expect, char **resultp) { + if (sudoerslval.string != NULL) { + free(sudoerslval.string); + sudoerslval.string = NULL; + } if (!fill(input, len)) return -1; *resultp = sudoerslval.string; @@ -108,6 +112,10 @@ check_fill(const char *input, int len, int addspace, const char *expect, char ** static int check_fill_cmnd(const char *input, int len, int addspace, const char *expect, char **resultp) { + if (sudoerslval.command.cmnd != NULL) { + free(sudoerslval.command.cmnd); + sudoerslval.command.cmnd = NULL; + } if (!fill_cmnd(input, len)) return -1; *resultp = sudoerslval.command.cmnd; @@ -117,6 +125,7 @@ check_fill_cmnd(const char *input, int len, int addspace, const char *expect, ch static int check_fill_args(const char *input, int len, int addspace, const char *expect, char **resultp) { + /* Must not free old sudoerslval.command.args as gets appended to. */ if (!fill_args(input, len, addspace)) return -1; *resultp = sudoerslval.command.args;