Skip to content

Commit e5fb028

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37766b6 commit e5fb028

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

builtin/for-each-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
9696
ref_array_clear(&array);
9797
free_commit_list(filter.with_commit);
9898
free_commit_list(filter.no_commit);
99-
UNLEAK(sorting);
99+
ref_sorting_release(sorting);
100100
return 0;
101101
}

builtin/tag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
630630
find_unique_abbrev(&prev, DEFAULT_ABBREV));
631631

632632
cleanup:
633+
ref_sorting_release(sorting);
633634
strbuf_release(&buf);
634635
strbuf_release(&ref);
635636
strbuf_release(&reflog_msg);

ref-filter.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,15 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
27052705
return 0;
27062706
}
27072707

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+
27082717
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
27092718
{
27102719
struct ref_filter *rf = opt->value;

ref-filter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
127127
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
128128
/* Default sort option based on refname */
129129
struct ref_sorting *ref_default_sorting(void);
130+
/* Release a "struct ref_sorting" */
131+
void ref_sorting_release(struct ref_sorting *);
130132
/* Function to parse --merged and --no-merged options */
131133
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
132134
/* Get the current HEAD's description */

0 commit comments

Comments
 (0)