Skip to content

Commit cdef625

Browse files
jonatan-holmgrengitster
authored andcommitted
git, help: fix memory leaks in alias listing
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>
1 parent 6589294 commit cdef625

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int list_cmds(const char *spec)
119119
}
120120
for (size_t i = 0; i < list.nr; i++)
121121
puts(list.items[i].string);
122-
string_list_clear(&list, 0);
122+
string_list_clear(&list, 1);
123123
return 0;
124124
}
125125

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void list_cmds_by_config(struct string_list *list)
423423
return;
424424

425425
string_list_sort(list);
426-
string_list_remove_duplicates(list, 0);
426+
string_list_remove_duplicates(list, 1);
427427

428428
while (*cmd_list) {
429429
struct strbuf sb = STRBUF_INIT;

0 commit comments

Comments
 (0)