]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add: plug a leak on interactive_add
authorRubén Justo <rjusto@gmail.com>
Mon, 22 Apr 2024 22:54:18 +0000 (00:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Apr 2024 23:27:43 +0000 (16:27 -0700)
Plug a leak we have since 5a76aff1a6 (add: convert to use
parse_pathspec, 2013-07-14).

This leak can be triggered with:
    $ git add -p anything

Fixing this leak allows us to mark as leak-free the following tests:

    + t3701-add-interactive.sh
    + t7514-commit-patch.sh

Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix
promply any new leak that may be introduced and triggered by them in the
future.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
t/t3701-add-interactive.sh
t/t7514-commit-patch.sh

index ae723bc85e63365903861cfb816d79b425deaf14..b7d3ff1e2841275e2ad6149239d2729735ddf5bd 100644 (file)
@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 int interactive_add(const char **argv, const char *prefix, int patch)
 {
        struct pathspec pathspec;
-       int unused;
+       int unused, ret;
 
        if (!git_config_get_bool("add.interactive.usebuiltin", &unused))
                warning(_("the add.interactive.useBuiltin setting has been removed!\n"
@@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch)
                       prefix, argv);
 
        if (patch)
-               return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
+               ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
        else
-               return !!run_add_i(the_repository, &pathspec);
+               ret = !!run_add_i(the_repository, &pathspec);
+
+       clear_pathspec(&pathspec);
+       return ret;
 }
 
 static int edit_patch(int argc, const char **argv, const char *prefix)
index bc55255b0a8da397ad14212035da9c4b9cb8d7d8..04d833337342cff2fd9842a0b555727b49644059 100755 (executable)
@@ -4,6 +4,7 @@ test_description='add -i basic tests'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
index b4de10a5ddac0a2a890adaeb559f1b2afea15bb3..03ba0c0e734e9b7ecc3ba4ac944af8fa83cd925a 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='hunk edit with "commit -p -m"'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup (initial)' '