Skip to content

Commit d72d4f9

Browse files
avargitster
authored andcommitted
branch: use ref_sorting_release()
Use a ref_sorting_release() in branch.c to free the memory from the ref_sorting_options(). This plugs the final in-tree memory leak of that API. In the preceding commit the "sorting" variable was left in the cmd_branch() scope, even though that wasn't needed anymore. Move it to the "else if (list)" scope instead. We can also move the "struct string_list" only used for that branch to be declared in that block That "struct ref_sorting" does not need to be "static" (and isn't re-used). The "ref_sorting_options()" will return a valid one, we don't need to make it "static" to have it zero'd out. That it was static was another artifact of the pre-image of the preceding commit. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5fb028 commit d72d4f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/branch.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
407407
return strbuf_detach(&fmt, NULL);
408408
}
409409

410-
static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting, struct ref_format *format)
410+
static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting,
411+
struct ref_format *format, struct string_list *output)
411412
{
412413
int i;
413414
struct ref_array array;
@@ -449,7 +450,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
449450
if (column_active(colopts)) {
450451
assert(!filter->verbose && "--column and --verbose are incompatible");
451452
/* format to a string_list to let print_columns() do its job */
452-
string_list_append(&output, out.buf);
453+
string_list_append(output, out.buf);
453454
} else {
454455
fwrite(out.buf, 1, out.len, stdout);
455456
putchar('\n');
@@ -753,9 +754,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
753754
ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
754755
ref_sorting_set_sort_flags_all(
755756
sorting, REF_SORTING_DETACHED_HEAD_FIRST, 1);
756-
print_ref_list(&filter, sorting, &format);
757+
print_ref_list(&filter, sorting, &format, &output);
757758
print_columns(&output, colopts, NULL);
758759
string_list_clear(&output, 0);
760+
ref_sorting_release(sorting);
759761
return 0;
760762
} else if (edit_description) {
761763
const char *branch_name;

0 commit comments

Comments
 (0)