Git fork

submodule: fix leaking submodule entry list

The submodule entry list returned by `submodules_of_tree()` is never
completely free'd by its only caller. Introduce a new function that
free's the list for us and call it.

While at it, also fix the leaking `branch_point` string.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
5cca1149 666643fa

+24 -3
+6 -2
branch.c
··· 738 738 739 739 strbuf_release(&child_err); 740 740 strbuf_release(&out_buf); 741 + free(out_prefix); 741 742 return ret; 742 743 } 743 744 ··· 794 795 create_branch(r, name, start_committish, force, 0, reflog, quiet, 795 796 BRANCH_TRACK_NEVER, dry_run); 796 797 if (dry_run) 797 - return; 798 + goto out; 798 799 /* 799 800 * NEEDSWORK If tracking was set up in the superproject but not the 800 801 * submodule, users might expect "git branch --recurse-submodules" to ··· 815 816 die(_("submodule '%s': cannot create branch '%s'"), 816 817 submodule_entry_list.entries[i].submodule->name, 817 818 name); 818 - repo_clear(submodule_entry_list.entries[i].repo); 819 819 } 820 + 821 + out: 822 + submodule_entry_list_release(&submodule_entry_list); 823 + free(branch_point); 820 824 } 821 825 822 826 void remove_merge_branch_state(struct repository *r)
+14 -1
submodule-config.c
··· 901 901 struct submodule_tree_entry *st_entry; 902 902 struct name_entry name_entry; 903 903 char *tree_path = NULL; 904 + char *tree_buf; 904 905 905 - fill_tree_descriptor(r, &tree, treeish_name); 906 + tree_buf = fill_tree_descriptor(r, &tree, treeish_name); 906 907 while (tree_entry(&tree, &name_entry)) { 907 908 if (prefix) 908 909 tree_path = ··· 930 931 &name_entry.oid, out); 931 932 free(tree_path); 932 933 } 934 + 935 + free(tree_buf); 933 936 } 934 937 935 938 void submodules_of_tree(struct repository *r, ··· 941 944 out->entry_alloc = 0; 942 945 943 946 traverse_tree_submodules(r, treeish_name, NULL, treeish_name, out); 947 + } 948 + 949 + void submodule_entry_list_release(struct submodule_entry_list *list) 950 + { 951 + for (size_t i = 0; i < list->entry_nr; i++) { 952 + free(list->entries[i].name_entry); 953 + repo_clear(list->entries[i].repo); 954 + free(list->entries[i].repo); 955 + } 956 + free(list->entries); 944 957 } 945 958 946 959 void submodule_free(struct repository *r)
+3
submodule-config.h
··· 136 136 void submodules_of_tree(struct repository *r, 137 137 const struct object_id *treeish_name, 138 138 struct submodule_entry_list *ret); 139 + 140 + void submodule_entry_list_release(struct submodule_entry_list *list); 141 + 139 142 #endif /* SUBMODULE_CONFIG_H */
+1
t/t3207-branch-submodule.sh
··· 5 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 7 8 + TEST_PASSES_SANITIZE_LEAK=true 8 9 . ./test-lib.sh 9 10 . "$TEST_DIRECTORY"/lib-rebase.sh 10 11