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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 26, 2024 at 13:46 UTC
5bf922a4e914f15d899d38218ad0591933025ed4
2 files changed
+10
-4
builtin/submodule--helper.c
+9
-4
@@ -2648,15 +2648,20 @@ static int update_submodule(struct update_data *update_data)
2648
2649
if (!update_data->nofetch) {
2650
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
2651
- 0, NULL))
2651
+ 0, NULL)) {
2652
+ free(remote_ref);
2653
return die_message(_("Unable to fetch in submodule path '%s'"),
2654
update_data->sm_path);
2655
+ }
2656
}
2657
2658
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
+ }
2665
2666
free(remote_ref);
2667
}
t/t7420-submodule-set-url.sh
+1
@@ -10,6 +10,7 @@ as expected.
10
'
11
12
TEST_NO_CREATE_REPO=1
13
+TEST_PASSES_SANITIZE_LEAK=true
14
. ./test-lib.sh
15
16
test_expect_success 'setup' '