diff mbox series

[02/20] convert: fix leaks when resetting attributes

Message ID ed0f01bf92c83fb7371326bd1a59933619de2c47.1724159575.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series Memory leak fixes (pt.5) | expand

Commit Message

Patrick Steinhardt Aug. 20, 2024, 2:05 p.m. UTC
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>
---
 convert.c     | 3 +++
 t/t4150-am.sh | 1 +
 2 files changed, 4 insertions(+)

Comments

Junio C Hamano Aug. 20, 2024, 7:51 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> 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>
> ---

The helper has only one caller, which makes me wonder why we do not
have to call it more often.  If "git checkout" or "log -p" notice an
attribute file is updated, I wonder they should call it, for
example.  But of course this is completely out of scope of this
topic.

This has been leaking even before 9642479a (convert: fix leaking
config strings, 2024-08-01) straightened out the ownership rules of
the value obtained from git_config_string().

The fix makes sense.  Will queue.  Thanks.
diff mbox series

Patch

diff --git a/convert.c b/convert.c
index e6184d21f26..c9a31eb4f03 100644
--- a/convert.c
+++ b/convert.c
@@ -1371,6 +1371,9 @@  void reset_parsed_attributes(void)
 	for (drv = user_convert; drv; drv = next) {
 		next = drv->next;
 		free((void *)drv->name);
+		free((void *)drv->smudge);
+		free((void *)drv->clean);
+		free((void *)drv->process);
 		free(drv);
 	}
 	user_convert = NULL;
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 5e2b6c80eae..232e1394e8d 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -5,6 +5,7 @@  test_description='git am running'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup: messages' '