builtin/show-ref: fix leaking string buffer

Fix a leaking string buffer in `git show-ref --exclude-existing`. While the buffer is technically not leaking because its variable is declared as static, there is no inherent reason why it should be. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Oct 31, 2023 at 09:16 UTC dbabd0b023b6a65267fd57ed04ecd47ac34b5ae5
1 file changed +3 -1
builtin/show-ref.c
+3 -1
@@ -106,7 +106,7 @@ static int add_existing(const char *refname,
106 */
107 static int cmd_show_ref__exclude_existing(const char *match)
108 {
109 - static struct string_list existing_refs = STRING_LIST_INIT_DUP;
109 + struct string_list existing_refs = STRING_LIST_INIT_DUP;
110 char buf[1024];
111 int matchlen = match ? strlen(match) : 0;
112
@@ -139,6 +139,8 @@ static int cmd_show_ref__exclude_existing(const char *match)
139 printf("%s\n", buf);
140 }
141 }
142 +
143 + string_list_clear(&existing_refs, 0);
144 return 0;
145 }
146