convert: fix leaks when resetting attributes

When resetting parsed gitattributes, we free the list of convert drivers
parsed from the config. We only free some of the drivers' fields though
and thus have memory leaks.

Fix this by freeing all allocated convert driver fields to plug these
memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-08-22 11:17:13 +02:00 committed by Junio C Hamano
parent e5530f9c5c
commit 643c6f576c
2 changed files with 4 additions and 0 deletions

View File

@ -1371,6 +1371,9 @@ void reset_parsed_attributes(void)
for (drv = user_convert; drv; drv = next) { for (drv = user_convert; drv; drv = next) {
next = drv->next; next = drv->next;
free((void *)drv->name); free((void *)drv->name);
free((void *)drv->smudge);
free((void *)drv->clean);
free((void *)drv->process);
free(drv); free(drv);
} }
user_convert = NULL; user_convert = NULL;

View File

@ -5,6 +5,7 @@ test_description='git am running'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
test_expect_success 'setup: messages' ' test_expect_success 'setup: messages' '