submodule--helper: add and use *_release() functions

Add release functions for "struct module_list", "struct submodule_update_clone" and "struct update_data". 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>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:14 UTC 87a683482a3982751fdc9d4252035d0cafab605d
2 files changed +28 -1
builtin/submodule--helper.c
+27 -1
@@ -172,6 +172,11 @@ struct module_list {
172 };
173 #define MODULE_LIST_INIT { 0 }
174
175 +static void module_list_release(struct module_list *ml)
176 +{
177 + free(ml->entries);
178 +}
179 +
180 static int module_list_compute(int argc, const char **argv,
181 const char *prefix,
182 struct pathspec *pathspec,
@@ -234,7 +239,7 @@ static void module_list_active(struct module_list *list)
239 active_modules.entries[active_modules.nr++] = ce;
240 }
241
237 - free(list->entries);
242 + module_list_release(list);
243 *list = active_modules;
244 }
245
@@ -407,6 +412,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
412
413 ret = 0;
414 cleanup:
415 + module_list_release(&list);
416 clear_pathspec(&pathspec);
417 return ret;
418 }
@@ -553,6 +559,7 @@ static int module_init(int argc, const char **argv, const char *prefix)
559
560 ret = 0;
561 cleanup:
562 + module_list_release(&list);
563 clear_pathspec(&pathspec);
564 return ret;
565 }
@@ -730,6 +737,7 @@ static int module_status(int argc, const char **argv, const char *prefix)
737
738 ret = 0;
739 cleanup:
740 + module_list_release(&list);
741 clear_pathspec(&pathspec);
742 return ret;
743 }
@@ -1302,6 +1310,7 @@ static int module_sync(int argc, const char **argv, const char *prefix)
1310
1311 ret = 0;
1312 cleanup:
1313 + module_list_release(&list);
1314 clear_pathspec(&pathspec);
1315 return ret;
1316 }
@@ -1454,6 +1463,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
1463
1464 ret = 0;
1465 cleanup:
1466 + module_list_release(&list);
1467 clear_pathspec(&pathspec);
1468 return ret;
1469 }
@@ -1831,6 +1841,12 @@ struct submodule_update_clone {
1841 };
1842 #define SUBMODULE_UPDATE_CLONE_INIT { 0 }
1843
1844 +static void submodule_update_clone_release(struct submodule_update_clone *suc)
1845 +{
1846 + free(suc->update_clone);
1847 + free(suc->failed_clones);
1848 +}
1849 +
1850 struct update_data {
1851 const char *prefix;
1852 const char *displaypath;
@@ -1869,6 +1885,11 @@ struct update_data {
1885 .max_jobs = 1, \
1886 }
1887
1888 +static void update_data_release(struct update_data *ud)
1889 +{
1890 + module_list_release(&ud->list);
1891 +}
1892 +
1893 static void next_submodule_warn_missing(struct submodule_update_clone *suc,
1894 struct strbuf *out, const char *displaypath)
1895 {
@@ -2554,6 +2575,7 @@ static int update_submodules(struct update_data *update_data)
2575 }
2576
2577 cleanup:
2578 + submodule_update_clone_release(&suc);
2579 string_list_clear(&update_data->references, 0);
2580 return ret;
2581 }
@@ -2651,6 +2673,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2673
2674 if (module_list_compute(argc, argv, opt.prefix,
2675 &pathspec2, &list) < 0) {
2676 + module_list_release(&list);
2677 ret = 1;
2678 goto cleanup;
2679 }
@@ -2667,10 +2690,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
2690 info.flags |= OPT_QUIET;
2691
2692 for_each_listed_submodule(&list, init_submodule_cb, &info);
2693 + module_list_release(&list);
2694 }
2695
2696 ret = update_submodules(&opt);
2697 cleanup:
2698 + update_data_release(&opt);
2699 list_objects_filter_release(&filter_options);
2700 clear_pathspec(&pathspec);
2701 clear_pathspec(&pathspec2);
@@ -2786,6 +2811,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2811 ret = 0;
2812 cleanup:
2813 clear_pathspec(&pathspec);
2814 + module_list_release(&list);
2815 return ret;
2816 }
2817
t/t6134-pathspec-in-submodule.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='test case exclude pathspec'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup a submodule' '