submodule--helper: fix a memory leak in get_default_remote_submodule()

Fix a memory leak in the get_default_remote_submodule() function added in a77c3fcb5ec (submodule--helper: get remote names from any repository, 2022-03-04), we need to repo_clear() the submodule we initialize. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:14 UTC ae3ef94d9bc61931636647c4eab558e09aaeb50a
1 file changed +5 -1
builtin/submodule--helper.c
+5 -1
@@ -65,12 +65,16 @@ static int repo_get_default_remote(struct repository *repo, char **default_remot
65 static int get_default_remote_submodule(const char *module_path, char **default_remote)
66 {
67 struct repository subrepo;
68 + int ret;
69
70 if (repo_submodule_init(&subrepo, the_repository, module_path,
71 null_oid()) < 0)
72 return die_message(_("could not get a repository handle for submodule '%s'"),
73 module_path);
73 - return repo_get_default_remote(&subrepo, default_remote);
74 + ret = repo_get_default_remote(&subrepo, default_remote);
75 + repo_clear(&subrepo);
76 +
77 + return ret;
78 }
79
80 static char *get_default_remote(void)