Skip to content

Commit 3e19816

Browse files
peffgitster
authored andcommitted
ls-remote: simplify UNLEAK() usage
We UNLEAK() the "sorting" list created by parsing command-line options (which is essentially used until the program exits). But we do so right before leaving the cmd_ls_remote() function, which means we have to hit all of the exits. But the point of UNLEAK() is that it's an annotation which doesn't impact the variable itself. We can mark it as soon as we're done writing its value, and then we only have to do so once. This gives us a minor code reduction, and serves as a better example of how UNLEAK() can be used. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5e1961 commit 3e19816

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

builtin/ls-remote.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
8383
PARSE_OPT_STOP_AT_NON_OPTION);
8484
dest = argv[0];
8585

86+
UNLEAK(sorting);
87+
8688
if (argc > 1) {
8789
int i;
8890
pattern = xcalloc(argc, sizeof(const char *));
@@ -107,7 +109,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
107109

108110
if (get_url) {
109111
printf("%s\n", *remote->url);
110-
UNLEAK(sorting);
111112
return 0;
112113
}
113114

@@ -122,10 +123,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
122123
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
123124
repo_set_hash_algo(the_repository, hash_algo);
124125
}
125-
if (transport_disconnect(transport)) {
126-
UNLEAK(sorting);
126+
if (transport_disconnect(transport))
127127
return 1;
128-
}
129128

130129
if (!dest && !quiet)
131130
fprintf(stderr, "From %s\n", *remote->url);
@@ -150,7 +149,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
150149
status = 0; /* we found something */
151150
}
152151

153-
UNLEAK(sorting);
154152
ref_array_clear(&ref_array);
155153
return status;
156154
}

0 commit comments

Comments
 (0)