diff mbox series

[v2,04/20] pretty: fix leaking key/value separator buffer

Message ID 1c368a4489a23e258ad66b2b10ec8721f7409b3a.1724315484.git.ps@pks.im (mailing list archive)
State Accepted
Commit 82ea7e59b26644f3e289d105bf85a4109749e4b8
Headers show
Series Memory leak fixes (pt.5) | expand

Commit Message

Patrick Steinhardt Aug. 22, 2024, 9:17 a.m. UTC
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>
---
 pretty.c                      | 1 +
 t/t4205-log-pretty-formats.sh | 2 ++
 2 files changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/pretty.c b/pretty.c
index 5e162d7204d..5e5ae452530 100644
--- 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;
 	}
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 158b49d4b60..eb63ce011fa 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -5,6 +5,8 @@ 
 #
 
 test_description='Test pretty formats'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # Tested non-UTF-8 encoding