pretty: fix leaking key/value separator buffer

The `format_set_trailers_options()` function is responsible for parsing a custom pretty format for trailers. It puts the parsed options into a `struct process_trailer_options` structure, while the allocated memory required for this will be put into separate caller-provided arguments. It is thus the caller's responsibility to free the memory not via the options structure, but via the other parameters. While we do this alright for the separator and filter keys, we do not free the memory associated with the key/value separator. Fix this to plug this memory leak. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 22, 2024 at 11:17 UTC 82ea7e59b26644f3e289d105bf85a4109749e4b8
2 files changed +3
pretty.c
+1
@@ -1776,6 +1776,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1776 }
1777 trailer_out:
1778 string_list_clear(&filter_list, 0);
1779 + strbuf_release(&kvsepbuf);
1780 strbuf_release(&sepbuf);
1781 return ret;
1782 }
t/t4205-log-pretty-formats.sh
+2
@@ -5,6 +5,8 @@
5 #
6
7 test_description='Test pretty formats'
8 +
9 +TEST_PASSES_SANITIZE_LEAK=true
10 . ./test-lib.sh
11
12 # Tested non-UTF-8 encoding