ref-filter API user: add and use a ref_sorting_release()
Add a ref_sorting_release() and use it for some of the current API users, the ref_sorting_default() function and its siblings will do a malloc() which wasn't being free'd previously. 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
e5fb028688f5811bd835c0bc47f8d7a379a0d152
4 files changed
+13
-1
builtin/for-each-ref.c
+1
-1
@@ -96,6 +96,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
96
ref_array_clear(&array);
97
free_commit_list(filter.with_commit);
98
free_commit_list(filter.no_commit);
99
- UNLEAK(sorting);
99
+ ref_sorting_release(sorting);
100
return 0;
101
}
builtin/tag.c
+1
@@ -630,6 +630,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
630
find_unique_abbrev(&prev, DEFAULT_ABBREV));
631
632
cleanup:
633
+ ref_sorting_release(sorting);
634
strbuf_release(&buf);
635
strbuf_release(&ref);
636
strbuf_release(&reflog_msg);
ref-filter.c
+9
@@ -2705,6 +2705,15 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
2705
return 0;
2706
}
2707
2708
+void ref_sorting_release(struct ref_sorting *sorting)
2709
+{
2710
+ while (sorting) {
2711
+ struct ref_sorting *next = sorting->next;
2712
+ free(sorting);
2713
+ sorting = next;
2714
+ }
2715
+}
2716
+
2717
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
2718
{
2719
struct ref_filter *rf = opt->value;
ref-filter.h
+2
@@ -127,6 +127,8 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
127
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
128
/* Default sort option based on refname */
129
struct ref_sorting *ref_default_sorting(void);
130
+/* Release a "struct ref_sorting" */
131
+void ref_sorting_release(struct ref_sorting *);
132
/* Function to parse --merged and --no-merged options */
133
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
134
/* Get the current HEAD's description */