Skip to content

Commit 25b6a95

Browse files
avargitster
authored andcommitted
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 a9f8a37 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06), but in 0b5e2ea (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 <[email protected]> Reviewed-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 623bd7d commit 25b6a95

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

builtin/submodule--helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,11 @@ static void print_status(unsigned int flags, char state, const char *path,
583583
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
584584

585585
if (state == ' ' || state == '+') {
586-
const char *name = compute_rev_name(path, oid_to_hex(oid));
586+
char *name = compute_rev_name(path, oid_to_hex(oid));
587587

588588
if (name)
589589
printf(" (%s)", name);
590+
free(name);
590591
}
591592

592593
printf("\n");

0 commit comments

Comments
 (0)