Skip to content

Commit 1672740

Browse files
rjustogitster
authored andcommitted
add: plug a leak on interactive_add
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec9b74b commit 1672740

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

builtin/add.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)
150150
int interactive_add(const char **argv, const char *prefix, int patch)
151151
{
152152
struct pathspec pathspec;
153-
int unused;
153+
int unused, ret;
154154

155155
if (!git_config_get_bool("add.interactive.usebuiltin", &unused))
156156
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)
163163
prefix, argv);
164164

165165
if (patch)
166-
return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
166+
ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
167167
else
168-
return !!run_add_i(the_repository, &pathspec);
168+
ret = !!run_add_i(the_repository, &pathspec);
169+
170+
clear_pathspec(&pathspec);
171+
return ret;
169172
}
170173

171174
static int edit_patch(int argc, const char **argv, const char *prefix)

t/t3701-add-interactive.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='add -i basic tests'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89
. "$TEST_DIRECTORY"/lib-terminal.sh
910

t/t7514-commit-patch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='hunk edit with "commit -p -m"'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'setup (initial)' '

0 commit comments

Comments
 (0)