Skip to content

Commit

Permalink
add: plug a leak on interactive_add
Browse files Browse the repository at this point in the history
Plug a leak we have since 5a76aff (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>
  • Loading branch information
rjusto authored and gitster committed Apr 22, 2024
1 parent ec9b74b commit 1672740
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions t/t3701-add-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions t/t7514-commit-patch.sh
Original file line number Diff line number Diff line change
@@ -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)' '
Expand Down

0 comments on commit 1672740

Please sign in to comment.