ls-remote & transport API: release "struct transport_ls_refs_options"

Fix a memory leak in codepaths that use the "struct
transport_ls_refs_options" API. Since the introduction of the struct
in 39835409d1 (connect, transport: encapsulate arg in struct,
2021-02-05) the caller has been responsible for freeing it.

That commit in turn migrated code originally added in
402c47d939 (clone: send ref-prefixes when using protocol v2,
2018-07-20) and b4be74105f (ls-remote: pass ref prefixes when
requesting a remote's refs, 2018-03-15). Only some of those codepaths
were releasing the allocated resources of the struct, now all of them
will.

Mark the "t/t5511-refspec.sh" test as passing when git is compiled
with SANITIZE=leak. They'll now be listed as running under the
"GIT_TEST_PASSING_SANITIZE_LEAK=true" test mode (the "linux-leaks" CI
target). Previously 24/47 tests would fail.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-02-05 01:08:14 +01:00
committed by Junio C Hamano
parent 38062e73e0
commit f36d4f8316
7 changed files with 26 additions and 15 deletions

View File

@ -1233,7 +1233,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
else {
const char *branch;
char *ref;
const char *ref;
char *ref_free = NULL;
if (option_branch)
die(_("Remote branch %s not found in upstream %s"),
@ -1250,17 +1251,16 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
skip_prefix(transport_ls_refs_options.unborn_head_target,
"refs/heads/", &branch)) {
ref = transport_ls_refs_options.unborn_head_target;
transport_ls_refs_options.unborn_head_target = NULL;
create_symref("HEAD", ref, reflog_msg.buf);
} else {
branch = git_default_branch_name(0);
ref = xstrfmt("refs/heads/%s", branch);
ref_free = xstrfmt("refs/heads/%s", branch);
ref = ref_free;
}
if (!option_bare)
install_branch_config(0, branch, remote_name, ref);
free(ref);
free(ref_free);
}
write_refspec_config(src_ref_prefix, our_head_points_at,
@ -1312,7 +1312,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
UNLEAK(repo);
junk_mode = JUNK_LEAVE_ALL;
strvec_clear(&transport_ls_refs_options.ref_prefixes);
free(transport_ls_refs_options.unborn_head_target);
transport_ls_refs_options_release(&transport_ls_refs_options);
return err;
}