submodule--helper: fix a memory leak in print_status()

Fix a leak in print_status(), the compute_rev_name() function
implemented in this file will return a strbuf_detach()'d value, or
NULL.

This leak has existed since this code was added in
a9f8a37584 (submodule: port submodule subcommand 'status' from shell
to C, 2017-10-06), but in 0b5e2ea7cf (submodule--helper: don't print
null in 'submodule status', 2018-04-18) we added a "const"
intermediate variable for the return value, that "const" should be
removed.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2022-09-01 01:14:21 +02:00 committed by Junio C Hamano
parent 623bd7d154
commit 25b6a95d03

View File

@ -583,10 +583,11 @@ static void print_status(unsigned int flags, char state, const char *path,
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
if (state == ' ' || state == '+') {
const char *name = compute_rev_name(path, oid_to_hex(oid));
char *name = compute_rev_name(path, oid_to_hex(oid));
if (name)
printf(" (%s)", name);
free(name);
}
printf("\n");