Skip to content

Commit 5bf922a

Browse files
pks-tgitster
authored andcommitted
builtin/submodule--helper: fix leaking remote ref on errors
When `update_submodule()` fails we return with `die_message()`, which only causes us to print the same message as `die()` would without actually causing the process to die. We don't free memory in that case and thus leak memory. Fix the leak by freeing the remote ref. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1652c0 commit 5bf922a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

builtin/submodule--helper.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,15 +2648,20 @@ static int update_submodule(struct update_data *update_data)
26482648

26492649
if (!update_data->nofetch) {
26502650
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
2651-
0, NULL))
2651+
0, NULL)) {
2652+
free(remote_ref);
26522653
return die_message(_("Unable to fetch in submodule path '%s'"),
26532654
update_data->sm_path);
2655+
}
26542656
}
26552657

26562658
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2657-
remote_ref, &update_data->oid))
2658-
return die_message(_("Unable to find %s revision in submodule path '%s'"),
2659-
remote_ref, update_data->sm_path);
2659+
remote_ref, &update_data->oid)) {
2660+
ret = die_message(_("Unable to find %s revision in submodule path '%s'"),
2661+
remote_ref, update_data->sm_path);
2662+
free(remote_ref);
2663+
return ret;
2664+
}
26602665

26612666
free(remote_ref);
26622667
}

t/t7420-submodule-set-url.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ as expected.
1010
'
1111

1212
TEST_NO_CREATE_REPO=1
13+
TEST_PASSES_SANITIZE_LEAK=true
1314
. ./test-lib.sh
1415

1516
test_expect_success 'setup' '

0 commit comments

Comments
 (0)