]> Kevux Git Server - rit/commitdiff
builtin/rerere: fix various trivial memory leaks
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2024 10:40:36 +0000 (12:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 15:47:37 +0000 (08:47 -0700)
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>
builtin/rerere.c
rerere.c
t/t2030-unresolve-info.sh
t/t4200-rerere.sh

index b2efc6f..81b65ff 100644 (file)
@@ -73,11 +73,17 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
 
        if (!strcmp(argv[0], "forget")) {
                struct pathspec pathspec;
+               int ret;
+
                if (argc < 2)
                        warning(_("'git rerere forget' without paths is deprecated"));
                parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
                               prefix, argv + 1);
-               return rerere_forget(the_repository, &pathspec);
+
+               ret = rerere_forget(the_repository, &pathspec);
+
+               clear_pathspec(&pathspec);
+               return ret;
        }
 
        if (!strcmp(argv[0], "clear")) {
index 3a3888c..525ed6c 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1107,7 +1107,7 @@ fail_exit:
 
 int rerere_forget(struct repository *r, struct pathspec *pathspec)
 {
-       int i, fd;
+       int i, fd, ret;
        struct string_list conflict = STRING_LIST_INIT_DUP;
        struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
@@ -1132,7 +1132,12 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
                        continue;
                rerere_forget_one_path(r->index, it->string, &merge_rr);
        }
-       return write_rr(&merge_rr, fd);
+
+       ret = write_rr(&merge_rr, fd);
+
+       string_list_clear(&conflict, 0);
+       string_list_clear(&merge_rr, 1);
+       return ret;
 }
 
 /*
index be3fcdd..b3f6bc9 100755 (executable)
@@ -5,6 +5,7 @@ test_description='undoing resolution'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 check_resolve_undo () {
index b0a3e84..213b36f 100755 (executable)
@@ -25,6 +25,7 @@ test_description='git rerere
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '