summaryrefslogtreecommitdiffstats
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-09-10 01:21:18 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-10 01:26:11 +0200
commitdb629c61f0be3665a36750fe2353b9ee958b0376 (patch)
treef825574355c43dbded14d148c86d1d64e9a51fc7 /ref-filter.c
parentref-filter: fix leak when formatting %(push:remoteref) (diff)
downloadgit-db629c61f0be3665a36750fe2353b9ee958b0376.tar.xz
git-db629c61f0be3665a36750fe2353b9ee958b0376.zip
ref-filter: add ref_format_clear() function
After using the ref-filter API, callers should use ref_filter_clear() to free any used memory. However, there's not a matching function to clear the ref_format struct. Traditionally this did not need to be cleaned up, as it was just a way for the caller to store and pass format options as a single unit. Even though the parsing step of some placeholders may allocate data, that's usually inside their "used_atom" structs, which are part of the ref_filter itself. But a few placeholders keep data outside of there. The %(ahead-behind) and %(is-base) parsers both keep a master list of bases, because they perform a single filtering pass outside of the use of any particular atom. And since the format parser does not have access to the ref_filter struct, they store their cross-atom data in the ref_format struct itself. And thus when they are finished, the ref_format also needs to be cleaned up. So let's add a function to do so, and call it from all of the users of the ref-filter API. The %(is-base) case is found by running LSan on t6300. After this patch, the script can now be marked leak-free. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 0f51095bbd..ce1bcfad85 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -3621,3 +3621,16 @@ void ref_filter_clear(struct ref_filter *filter)
free_commit_list(filter->unreachable_from);
ref_filter_init(filter);
}
+
+void ref_format_init(struct ref_format *format)
+{
+ struct ref_format blank = REF_FORMAT_INIT;
+ memcpy(format, &blank, sizeof(blank));
+}
+
+void ref_format_clear(struct ref_format *format)
+{
+ string_list_clear(&format->bases, 0);
+ string_list_clear(&format->is_base_tips, 0);
+ ref_format_init(format);
+}