]> git.ipfire.org Git - thirdparty/git.git/commit
ref-filter: fix leak with unterminated %(if) atoms
authorPatrick Steinhardt <ps@pks.im>
Tue, 10 Sep 2024 06:57:15 +0000 (08:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Sep 2024 16:26:13 +0000 (09:26 -0700)
commit04d9744f839dc90f27f08f94cc26f8bb33b3adfa
treede0ce881b85017f45a0060e5e5d6aa344ae877cb
parentdb629c61f0be3665a36750fe2353b9ee958b0376
ref-filter: fix leak with unterminated %(if) atoms

When parsing `%(if)` atoms we expect a few other atoms to exist to
complete it, like `%(then)` and `%(end)`. Whether or not we have seen
these other atoms is tracked in an allocated `if_then_else` structure,
which gets free'd by the `if_then_else_handler()` once we have parsed
the complete conditional expression.

This results in a memory leak when the `%(if)` atom is not terminated
correctly and thus incomplete. We never end up executing its handler and
thus don't end up freeing the structure.

Plug this memory leak by introducing a new `at_end_data_free` callback
function. If set, we'll execute it in `pop_stack_element()` and pass it
the `at_end_data` variable with the intent to free its state. Wire it up
for the `%(if)` atom accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ref-filter.c
t/t6302-for-each-ref-filter.sh