Skip to content

Commit 81e5c39

Browse files
avargitster
authored andcommitted
clone: use free() instead of UNLEAK()
Change an UNLEAK() added in 0c45427 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8ed0a8 commit 81e5c39

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/clone.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
892892
int is_bundle = 0, is_local;
893893
int reject_shallow = 0;
894894
const char *repo_name, *repo, *work_tree, *git_dir;
895+
char *repo_to_free = NULL;
895896
char *path = NULL, *dir, *display_repo = NULL;
896897
int dest_exists, real_dest_exists = 0;
897898
const struct ref *refs, *remote_head;
@@ -949,7 +950,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
949950
path = get_repo_path(repo_name, &is_bundle);
950951
if (path) {
951952
FREE_AND_NULL(path);
952-
repo = absolute_pathdup(repo_name);
953+
repo = repo_to_free = absolute_pathdup(repo_name);
953954
} else if (strchr(repo_name, ':')) {
954955
repo = repo_name;
955956
display_repo = transport_anonymize_url(repo);
@@ -1413,7 +1414,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
14131414
free(unborn_head);
14141415
free(dir);
14151416
free(path);
1416-
UNLEAK(repo);
1417+
free(repo_to_free);
14171418
junk_mode = JUNK_LEAVE_ALL;
14181419

14191420
transport_ls_refs_options_release(&transport_ls_refs_options);

0 commit comments

Comments
 (0)