Skip to content

Commit 50ef4e0

Browse files
pks-tgitster
authored andcommitted
builtin/rerere: fix various trivial memory leaks
There are multiple trivial memory leaks in git-rerere(1). Fix those. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d615af commit 50ef4e0

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

builtin/rerere.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,17 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
7373

7474
if (!strcmp(argv[0], "forget")) {
7575
struct pathspec pathspec;
76+
int ret;
77+
7678
if (argc < 2)
7779
warning(_("'git rerere forget' without paths is deprecated"));
7880
parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
7981
prefix, argv + 1);
80-
return rerere_forget(the_repository, &pathspec);
82+
83+
ret = rerere_forget(the_repository, &pathspec);
84+
85+
clear_pathspec(&pathspec);
86+
return ret;
8187
}
8288

8389
if (!strcmp(argv[0], "clear")) {

rerere.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ static int rerere_forget_one_path(struct index_state *istate,
11071107

11081108
int rerere_forget(struct repository *r, struct pathspec *pathspec)
11091109
{
1110-
int i, fd;
1110+
int i, fd, ret;
11111111
struct string_list conflict = STRING_LIST_INIT_DUP;
11121112
struct string_list merge_rr = STRING_LIST_INIT_DUP;
11131113

@@ -1132,7 +1132,12 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
11321132
continue;
11331133
rerere_forget_one_path(r->index, it->string, &merge_rr);
11341134
}
1135-
return write_rr(&merge_rr, fd);
1135+
1136+
ret = write_rr(&merge_rr, fd);
1137+
1138+
string_list_clear(&conflict, 0);
1139+
string_list_clear(&merge_rr, 1);
1140+
return ret;
11361141
}
11371142

11381143
/*

t/t2030-unresolve-info.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='undoing resolution'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
check_resolve_undo () {

t/t4200-rerere.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test_description='git rerere
2525
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
2626
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
2727

28+
TEST_PASSES_SANITIZE_LEAK=true
2829
. ./test-lib.sh
2930

3031
test_expect_success 'setup' '

0 commit comments

Comments
 (0)