From: Ævar Arnfjörð Bjarmason Date: Wed, 31 Aug 2022 23:14:21 +0000 (+0200) Subject: submodule--helper: fix a memory leak in print_status() X-Git-Tag: v2.38.0-rc0~7^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25b6a95d03fe4fbb7acb8bbd0e1faad9a7f4ea9b;p=thirdparty%2Fgit.git 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 a9f8a37584a (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06), but in 0b5e2ea7cf3 (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 Reviewed-by: Glen Choo Signed-off-by: Junio C Hamano --- diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5c9a59083f..23c4f8d576 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -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");