]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: fix a memory leak in get_default_remote_submodule()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 31 Aug 2022 23:14:17 +0000 (01:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Sep 2022 16:18:13 +0000 (09:18 -0700)
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>
builtin/submodule--helper.c

index 79ffcb50909846c470261842b4abc632b5e870e4..8866af22501a7ce048448724aa5ec015df08534f 100644 (file)
@@ -65,12 +65,16 @@ static int repo_get_default_remote(struct repository *repo, char **default_remot
 static int get_default_remote_submodule(const char *module_path, char **default_remote)
 {
        struct repository subrepo;
+       int ret;
 
        if (repo_submodule_init(&subrepo, the_repository, module_path,
                                null_oid()) < 0)
                return die_message(_("could not get a repository handle for submodule '%s'"),
                                   module_path);
-       return repo_get_default_remote(&subrepo, default_remote);
+       ret = repo_get_default_remote(&subrepo, default_remote);
+       repo_clear(&subrepo);
+
+       return ret;
 }
 
 static char *get_default_remote(void)