]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty: fix leaking key/value separator buffer
authorPatrick Steinhardt <ps@pks.im>
Thu, 22 Aug 2024 09:17:18 +0000 (11:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2024 16:18:04 +0000 (09:18 -0700)
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>
pretty.c
t/t4205-log-pretty-formats.sh

index 5e162d7204d68b4411cd586047e1b152e020852c..5e5ae452530cca131ce97f342a242e895b6b6c69 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1776,6 +1776,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                }
        trailer_out:
                string_list_clear(&filter_list, 0);
+               strbuf_release(&kvsepbuf);
                strbuf_release(&sepbuf);
                return ret;
        }
index 158b49d4b603d10d5fe802fb7888c0257a754d88..eb63ce011fa646d0a8992bc505068fd5ac1a57e8 100755 (executable)
@@ -5,6 +5,8 @@
 #
 
 test_description='Test pretty formats'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # Tested non-UTF-8 encoding