builtin/rerere: fix various trivial memory leaks

There are multiple trivial memory leaks in git-rerere(1). Fix those. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 1, 2024 at 12:40 UTC 50ef4e09c386f46898886b1c3ae8bef5783b4e90
4 files changed +16 -3
builtin/rerere.c
+7 -1
@@ -73,11 +73,17 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
73
74 if (!strcmp(argv[0], "forget")) {
75 struct pathspec pathspec;
76 + int ret;
77 +
78 if (argc < 2)
79 warning(_("'git rerere forget' without paths is deprecated"));
80 parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
81 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;
87 }
88
89 if (!strcmp(argv[0], "clear")) {
rerere.c
+7 -2
@@ -1107,7 +1107,7 @@ fail_exit:
1107
1108 int rerere_forget(struct repository *r, struct pathspec *pathspec)
1109 {
1110 - int i, fd;
1110 + int i, fd, ret;
1111 struct string_list conflict = STRING_LIST_INIT_DUP;
1112 struct string_list merge_rr = STRING_LIST_INIT_DUP;
1113
@@ -1132,7 +1132,12 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
1132 continue;
1133 rerere_forget_one_path(r->index, it->string, &merge_rr);
1134 }
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;
1141 }
1142
1143 /*
t/t2030-unresolve-info.sh
+1
@@ -5,6 +5,7 @@ test_description='undoing resolution'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 check_resolve_undo () {
t/t4200-rerere.sh
+1
@@ -25,6 +25,7 @@ test_description='git rerere
25 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
26 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
27
28 +TEST_PASSES_SANITIZE_LEAK=true
29 . ./test-lib.sh
30
31 test_expect_success 'setup' '