]> granicus.if.org Git - sudo/commitdiff
Plug some memory leaks in the tests.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 29 Jan 2016 18:34:09 +0000 (11:34 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 29 Jan 2016 18:34:09 +0000 (11:34 -0700)
plugins/sudoers/regress/iolog_path/check_iolog_path.c
plugins/sudoers/regress/parser/check_fill.c

index dd06d4c844d4f446fa5b51494044e63e22af274a..fd3a5188fa975ba5b4a4121810e072eccce8462f 100644 (file)
@@ -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:
index 85dce0faf7e0962f7611caaa2e7ab4009d338cff..8d59e55380abde89629520215bd15d17c625ffe5 100644 (file)
@@ -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;