]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter API user: add and use a ref_sorting_release()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 20 Oct 2021 18:27:20 +0000 (20:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Oct 2021 18:36:13 +0000 (11:36 -0700)
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>
builtin/for-each-ref.c
builtin/tag.c
ref-filter.c
ref-filter.h

index 642b4b888fbe88eaa3d1b28a7bd6eaed092540f1..16a2c7d57ca40a891f6fac7e5674ad8a045536e4 100644 (file)
@@ -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;
 }
index ad6c98559149b52a65bd7224249552c058f25213..6fe646710d6ffbf242dda3bf7a5c27742acc0ef3 100644 (file)
@@ -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);
index add429be7973634ef99c26847b90e15b146d9f4d..282cdad1036e24eb1de57b97c810bbdbfda558fb 100644 (file)
@@ -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;
index b636f4389d0507d870ece2bba0f0e6ceb5d951e7..6228458d30673c21a2b2eb6bf2537de4beea01fb 100644 (file)
@@ -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 */