summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-10-20 18:27:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-10-20 18:36:13 (GMT)
commite5fb028688f5811bd835c0bc47f8d7a379a0d152 (patch)
treea9e8e75d8139818d8f39240d5ef5bb9ce27ac179
parent37766b61cdb3e12709febcd2f9dbee2b90e62969 (diff)
downloadgit-e5fb028688f5811bd835c0bc47f8d7a379a0d152.zip
git-e5fb028688f5811bd835c0bc47f8d7a379a0d152.tar.gz
git-e5fb028688f5811bd835c0bc47f8d7a379a0d152.tar.bz2
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>
-rw-r--r--builtin/for-each-ref.c2
-rw-r--r--builtin/tag.c1
-rw-r--r--ref-filter.c9
-rw-r--r--ref-filter.h2
4 files changed, 13 insertions, 1 deletions
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 642b4b8..16a2c7d 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -96,6 +96,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
ref_array_clear(&array);
free_commit_list(filter.with_commit);
free_commit_list(filter.no_commit);
- UNLEAK(sorting);
+ ref_sorting_release(sorting);
return 0;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index ad6c985..6fe6467 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -630,6 +630,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
find_unique_abbrev(&prev, DEFAULT_ABBREV));
cleanup:
+ ref_sorting_release(sorting);
strbuf_release(&buf);
strbuf_release(&ref);
strbuf_release(&reflog_msg);
diff --git a/ref-filter.c b/ref-filter.c
index add429b..282cdad 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2705,6 +2705,15 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
return 0;
}
+void ref_sorting_release(struct ref_sorting *sorting)
+{
+ while (sorting) {
+ struct ref_sorting *next = sorting->next;
+ free(sorting);
+ sorting = next;
+ }
+}
+
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
{
struct ref_filter *rf = opt->value;
diff --git a/ref-filter.h b/ref-filter.h
index b636f43..6228458 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -127,6 +127,8 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
/* Default sort option based on refname */
struct ref_sorting *ref_default_sorting(void);
+/* Release a "struct ref_sorting" */
+void ref_sorting_release(struct ref_sorting *);
/* Function to parse --merged and --no-merged options */
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
/* Get the current HEAD's description */