aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-26 13:46:21 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-27 08:25:35 -0700
commit5bf922a4e914f15d899d38218ad0591933025ed4 (patch)
treeb550eb0e0393450a0295b679d4f4e71111c8bab3 /builtin/submodule--helper.c
parentf1652c04b5da814a6bd15873a0a0323bf58badcf (diff)
downloadgit-5bf922a4e914f15d899d38218ad0591933025ed4.tar.gz
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>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ff1376f69f..a9bd93a785 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2648,15 +2648,20 @@ static int update_submodule(struct update_data *update_data)
if (!update_data->nofetch) {
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
- 0, NULL))
+ 0, NULL)) {
+ free(remote_ref);
return die_message(_("Unable to fetch in submodule path '%s'"),
update_data->sm_path);
+ }
}
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
- remote_ref, &update_data->oid))
- return die_message(_("Unable to find %s revision in submodule path '%s'"),
- remote_ref, update_data->sm_path);
+ remote_ref, &update_data->oid)) {
+ ret = die_message(_("Unable to find %s revision in submodule path '%s'"),
+ remote_ref, update_data->sm_path);
+ free(remote_ref);
+ return ret;
+ }
free(remote_ref);
}