Skip to content

Commit 2e492f2

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3aef7a0 commit 2e492f2

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

builtin/submodule--helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,7 @@ struct update_data {
20212021
static void update_data_release(struct update_data *ud)
20222022
{
20232023
free(ud->displaypath);
2024+
submodule_update_strategy_release(&ud->update_strategy);
20242025
module_list_release(&ud->list);
20252026
}
20262027

submodule-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void free_one_config(struct submodule_entry *entry)
9595
free((void *) entry->config->branch);
9696
free((void *) entry->config->url);
9797
free((void *) entry->config->ignore);
98-
free((void *) entry->config->update_strategy.command);
98+
submodule_update_strategy_release(&entry->config->update_strategy);
9999
free(entry->config);
100100
}
101101

submodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ int parse_submodule_update_strategy(const char *value,
424424
return 0;
425425
}
426426

427+
void submodule_update_strategy_release(struct submodule_update_strategy *strategy)
428+
{
429+
free((char *) strategy->command);
430+
}
431+
427432
const char *submodule_update_type_to_string(enum submodule_update_type type)
428433
{
429434
switch (type) {

submodule.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ struct submodule_update_strategy {
4141
.type = SM_UPDATE_UNSPECIFIED, \
4242
}
4343

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+
4448
int is_gitmodules_unmerged(struct index_state *istate);
4549
int is_writing_gitmodules_ok(void);
4650
int is_staging_gitmodules_ok(struct index_state *istate);
@@ -70,8 +74,6 @@ void die_in_unpopulated_submodule(struct index_state *istate,
7074
void die_path_inside_submodule(struct index_state *istate,
7175
const struct pathspec *ps);
7276
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);
7577
const char *submodule_update_type_to_string(enum submodule_update_type type);
7678
void handle_ignore_submodules_arg(struct diff_options *, const char *);
7779
void show_submodule_diff_summary(struct diff_options *o, const char *path,

t/t7406-submodule-update.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
1212
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1313
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1414

15+
TEST_PASSES_SANITIZE_LEAK=true
1516
. ./test-lib.sh
1617

1718

0 commit comments

Comments
 (0)