clone: use free() instead of UNLEAK()

Change an UNLEAK() added in 0c4542738e6 (clone: free or UNLEAK further pointers when finished, 2021-03-14) to use a "to_free" pattern instead. In this case the "repo" can be either this absolute_pathdup() value, or in the "else if" branch seen in the context the the "argv[0]" argument to "main()". We can only free() the value in the former case, hence the "to_free" pattern. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 7, 2023 at 00:07 UTC 81e5c39cf63b414468adcc6601184212e68e1fc1
1 file changed +3 -2
builtin/clone.c
+3 -2
@@ -892,6 +892,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
892 int is_bundle = 0, is_local;
893 int reject_shallow = 0;
894 const char *repo_name, *repo, *work_tree, *git_dir;
895 + char *repo_to_free = NULL;
896 char *path = NULL, *dir, *display_repo = NULL;
897 int dest_exists, real_dest_exists = 0;
898 const struct ref *refs, *remote_head;
@@ -949,7 +950,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
950 path = get_repo_path(repo_name, &is_bundle);
951 if (path) {
952 FREE_AND_NULL(path);
952 - repo = absolute_pathdup(repo_name);
953 + repo = repo_to_free = absolute_pathdup(repo_name);
954 } else if (strchr(repo_name, ':')) {
955 repo = repo_name;
956 display_repo = transport_anonymize_url(repo);
@@ -1413,7 +1414,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1414 free(unborn_head);
1415 free(dir);
1416 free(path);
1416 - UNLEAK(repo);
1417 + free(repo_to_free);
1418 junk_mode = JUNK_LEAVE_ALL;
1419
1420 transport_ls_refs_options_release(&transport_ls_refs_options);