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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 20, 2021 at 20:27 UTC d72d4f92e2e0fed38c6173c31e86b1b8881600e8
1 file changed +5 -3
builtin/branch.c
+5 -3
@@ -407,7 +407,8 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
407 return strbuf_detach(&fmt, NULL);
408 }
409
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)
412 {
413 int i;
414 struct ref_array array;
@@ -449,7 +450,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
450 if (column_active(colopts)) {
451 assert(!filter->verbose && "--column and --verbose are incompatible");
452 /* 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);
454 } else {
455 fwrite(out.buf, 1, out.len, stdout);
456 putchar('\n');
@@ -753,9 +754,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
754 ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
755 ref_sorting_set_sort_flags_all(
756 sorting, REF_SORTING_DETACHED_HEAD_FIRST, 1);
756 - print_ref_list(&filter, sorting, &format);
757 + print_ref_list(&filter, sorting, &format, &output);
758 print_columns(&output, colopts, NULL);
759 string_list_clear(&output, 0);
760 + ref_sorting_release(sorting);
761 return 0;
762 } else if (edit_description) {
763 const char *branch_name;