]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git, help: fix memory leaks in alias listing
authorJonatan Holmgren <jonatan@jontes.page>
Thu, 26 Feb 2026 20:53:28 +0000 (21:53 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Feb 2026 21:07:24 +0000 (13:07 -0800)
The list_aliases() function sets the util pointer of each list item to
a heap-allocated copy of the alias command value.  Two callers failed
to free these util pointers:

 - list_cmds() in git.c collects a string list with STRING_LIST_INIT_DUP
   and clears it with string_list_clear(&list, 0), which frees the
   duplicated strings (strdup_strings=1) but not the util pointers.
   Pass free_util=1 to free them.

 - list_cmds_by_config() in help.c calls string_list_sort_u(list, 0) to
   deduplicate the list before processing completion.commands overrides.
   When duplicate entries are removed, the util pointer of each discarded
   item is leaked because free_util=0.  Pass free_util=1 to free them.

Reported-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jonatan Holmgren <jonatan@jontes.page>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git.c
help.c

diff --git a/git.c b/git.c
index c5fad56813f437cac4e3f52a7f96b2dc594fa25a..b5eb740e834ac36751a355d6611bfa1b0330e01f 100644 (file)
--- a/git.c
+++ b/git.c
@@ -119,7 +119,7 @@ static int list_cmds(const char *spec)
        }
        for (size_t i = 0; i < list.nr; i++)
                puts(list.items[i].string);
-       string_list_clear(&list, 0);
+       string_list_clear(&list, 1);
        return 0;
 }
 
diff --git a/help.c b/help.c
index 82fb2eaa3f05120807e4d30e0b225c3c5b30155b..725e92a1958eeb81da94e430a3fdd7c683a115f5 100644 (file)
--- a/help.c
+++ b/help.c
@@ -423,7 +423,7 @@ void list_cmds_by_config(struct string_list *list)
                return;
 
        string_list_sort(list);
-       string_list_remove_duplicates(list, 0);
+       string_list_remove_duplicates(list, 1);
 
        while (*cmd_list) {
                struct strbuf sb = STRBUF_INIT;