submodule: fix leaking update strategy

We're not freeing the submodule update strategy command. Provide a helper function that does this for us and call it in `update_data_release()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 26, 2024 at 13:46 UTC 2e492f2047748cf70350d503214ef89f1110ee82
5 files changed +12 -3
builtin/submodule--helper.c
+1
@@ -2021,6 +2021,7 @@ struct update_data {
2021 static void update_data_release(struct update_data *ud)
2022 {
2023 free(ud->displaypath);
2024 + submodule_update_strategy_release(&ud->update_strategy);
2025 module_list_release(&ud->list);
2026 }
2027
submodule-config.c
+1 -1
@@ -95,7 +95,7 @@ static void free_one_config(struct submodule_entry *entry)
95 free((void *) entry->config->branch);
96 free((void *) entry->config->url);
97 free((void *) entry->config->ignore);
98 - free((void *) entry->config->update_strategy.command);
98 + submodule_update_strategy_release(&entry->config->update_strategy);
99 free(entry->config);
100 }
101
submodule.c
+5
@@ -424,6 +424,11 @@ int parse_submodule_update_strategy(const char *value,
424 return 0;
425 }
426
427 +void submodule_update_strategy_release(struct submodule_update_strategy *strategy)
428 +{
429 + free((char *) strategy->command);
430 +}
431 +
432 const char *submodule_update_type_to_string(enum submodule_update_type type)
433 {
434 switch (type) {
submodule.h
+4 -2
@@ -41,6 +41,10 @@ struct submodule_update_strategy {
41 .type = SM_UPDATE_UNSPECIFIED, \
42 }
43
44 +int parse_submodule_update_strategy(const char *value,
45 + struct submodule_update_strategy *dst);
46 +void submodule_update_strategy_release(struct submodule_update_strategy *strategy);
47 +
48 int is_gitmodules_unmerged(struct index_state *istate);
49 int is_writing_gitmodules_ok(void);
50 int is_staging_gitmodules_ok(struct index_state *istate);
@@ -70,8 +74,6 @@ void die_in_unpopulated_submodule(struct index_state *istate,
74 void die_path_inside_submodule(struct index_state *istate,
75 const struct pathspec *ps);
76 enum submodule_update_type parse_submodule_update_type(const char *value);
73 -int parse_submodule_update_strategy(const char *value,
74 - struct submodule_update_strategy *dst);
77 const char *submodule_update_type_to_string(enum submodule_update_type type);
78 void handle_ignore_submodules_arg(struct diff_options *, const char *);
79 void show_submodule_diff_summary(struct diff_options *o, const char *path,
t/t7406-submodule-update.sh
+1
@@ -12,6 +12,7 @@ submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
12 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14
15 +TEST_PASSES_SANITIZE_LEAK=true
16 . ./test-lib.sh
17
18