]> git.ipfire.org Git - thirdparty/git.git/commit
trailer: fix leaking strbufs when formatting trailers
authorPatrick Steinhardt <ps@pks.im>
Tue, 5 Nov 2024 06:17:17 +0000 (07:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Nov 2024 06:37:54 +0000 (22:37 -0800)
commitff31b7b941286d91d03ddf4faac22b99149ea4b1
tree61a3396d20cc1d83d97b095f9ebb9886b63ac178
parent3f692fe5beb817fbb22754281dfb5ebf8863d0a3
trailer: fix leaking strbufs when formatting trailers

When formatting trailer lines we iterate through each of the trailers
and munge their respective token/value pairs according to the trailer
options. When formatting a trailer that has its `item->token` pointer
set we perform the munging in two local buffers. In the case where we
figure out that the value is empty and `trim_empty` is set we just skip
over the trailer item. But the buffers are local to the loop and we
don't release their contents, leading to a memory leak.

Plug this leak by lifting the buffers outside of the loop and releasing
them on function return. This fixes the memory leaks, but also optimizes
the loop as we don't have to reallocate the buffers on every single
iteration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7513-interpret-trailers.sh
trailer.c