Skip to content

Commit 54e8654

Browse files
pks-tgitster
authored andcommitted
builtin/branch: fix leaking sorting options
The sorting options are leaking, but given that they are marked with `UNLEAK()` the leak sanitizer doesn't complain. Fix the leak by creating a common exit path and clearing the vector such that we can get rid of the `UNLEAK()` annotation entirely. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a65ffc commit 54e8654

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

builtin/branch.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ int cmd_branch(int argc,
722722
static struct ref_sorting *sorting;
723723
struct string_list sorting_options = STRING_LIST_INIT_DUP;
724724
struct ref_format format = REF_FORMAT_INIT;
725+
int ret;
725726

726727
struct option options[] = {
727728
OPT_GROUP(N_("Generic options")),
@@ -851,15 +852,15 @@ int cmd_branch(int argc,
851852
if (list)
852853
setup_auto_pager("branch", 1);
853854

854-
UNLEAK(sorting_options);
855-
856855
if (delete) {
857856
if (!argc)
858857
die(_("branch name required"));
859-
return delete_branches(argc, argv, delete > 1, filter.kind, quiet);
858+
ret = delete_branches(argc, argv, delete > 1, filter.kind, quiet);
859+
goto out;
860860
} else if (show_current) {
861861
print_current_branch_name();
862-
return 0;
862+
ret = 0;
863+
goto out;
863864
} else if (list) {
864865
/* git branch --list also shows HEAD when it is detached */
865866
if ((filter.kind & FILTER_REFS_BRANCHES) && filter.detached)
@@ -882,12 +883,13 @@ int cmd_branch(int argc,
882883
ref_sorting_release(sorting);
883884
ref_filter_clear(&filter);
884885
ref_format_clear(&format);
885-
return 0;
886+
887+
ret = 0;
888+
goto out;
886889
} else if (edit_description) {
887890
const char *branch_name;
888891
struct strbuf branch_ref = STRBUF_INIT;
889892
struct strbuf buf = STRBUF_INIT;
890-
int ret = 1; /* assume failure */
891893

892894
if (!argc) {
893895
if (filter.detached)
@@ -901,18 +903,22 @@ int cmd_branch(int argc,
901903
}
902904

903905
strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
904-
if (!refs_ref_exists(get_main_ref_store(the_repository), branch_ref.buf))
906+
if (!refs_ref_exists(get_main_ref_store(the_repository), branch_ref.buf)) {
905907
error((!argc || branch_checked_out(branch_ref.buf))
906908
? _("no commit on branch '%s' yet")
907909
: _("no branch named '%s'"),
908910
branch_name);
909-
else if (!edit_branch_description(branch_name))
911+
ret = 1;
912+
} else if (!edit_branch_description(branch_name)) {
910913
ret = 0; /* happy */
914+
} else {
915+
ret = 1;
916+
}
911917

912918
strbuf_release(&branch_ref);
913919
strbuf_release(&buf);
914920

915-
return ret;
921+
goto out;
916922
} else if (copy || rename) {
917923
if (!argc)
918924
die(_("branch name required"));
@@ -1000,12 +1006,17 @@ int cmd_branch(int argc,
10001006
create_branches_recursively(the_repository, branch_name,
10011007
start_name, NULL, force,
10021008
reflog, quiet, track, 0);
1003-
return 0;
1009+
ret = 0;
1010+
goto out;
10041011
}
10051012
create_branch(the_repository, branch_name, start_name, force, 0,
10061013
reflog, quiet, track, 0);
10071014
} else
10081015
usage_with_options(builtin_branch_usage, options);
10091016

1010-
return 0;
1017+
ret = 0;
1018+
1019+
out:
1020+
string_list_clear(&sorting_options, 0);
1021+
return ret;
10111022
}

0 commit comments

Comments
 (0)