Skip to content

Commit 980416e

Browse files
avargitster
authored andcommitted
submodule--helper: fix "sm_path" and other "module_cb_list" leaks
Fix leaks in "struct module_cb_list" and the "struct module_cb" which it contains, these fix leaks in e83e333 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13). The "sm_path" should always have been a "char *", not a "const char *", we always create it with xstrdup(). We can't mark any tests passing passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true" as a result of this change, but "t7401-submodule-summary.sh" gets closer to passing as a result of this change. 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 61adac6 commit 980416e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

builtin/submodule--helper.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,16 +748,34 @@ struct module_cb {
748748
struct object_id oid_src;
749749
struct object_id oid_dst;
750750
char status;
751-
const char *sm_path;
751+
char *sm_path;
752752
};
753753
#define MODULE_CB_INIT { 0 }
754754

755+
static void module_cb_release(struct module_cb *mcb)
756+
{
757+
free(mcb->sm_path);
758+
}
759+
755760
struct module_cb_list {
756761
struct module_cb **entries;
757762
int alloc, nr;
758763
};
759764
#define MODULE_CB_LIST_INIT { 0 }
760765

766+
static void module_cb_list_release(struct module_cb_list *mcbl)
767+
{
768+
int i;
769+
770+
for (i = 0; i < mcbl->nr; i++) {
771+
struct module_cb *mcb = mcbl->entries[i];
772+
773+
module_cb_release(mcb);
774+
free(mcb);
775+
}
776+
free(mcbl->entries);
777+
}
778+
761779
struct summary_cb {
762780
int argc;
763781
const char **argv;
@@ -1101,6 +1119,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
11011119
cleanup:
11021120
strvec_clear(&diff_args);
11031121
release_revisions(&rev);
1122+
module_cb_list_release(&list);
11041123
return ret;
11051124
}
11061125

t/t7401-submodule-summary.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This test script tries to verify the sanity of summary subcommand of git submodu
1717
# various reasons, one of them being that there are lots of commands taking place
1818
# outside of 'test_expect_success' block, which is no longer in good-style.
1919

20+
TEST_PASSES_SANITIZE_LEAK=true
2021
. ./test-lib.sh
2122

2223
add_file () {

0 commit comments

Comments
 (0)