promisor-remote: fix leaking partial clone filter

The partial clone filter of a promisor remote is never free'd, causing memory leaks. Furthermore, in case multiple partial clone filters are defined for the same remote, we'd overwrite previous values without freeing them. Fix these leaks. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 26, 2024 at 13:46 UTC 355b3190ee208594ab122eace8a20f17d668e21c
2 files changed +3
promisor-remote.c
+2
@@ -154,6 +154,7 @@ static int promisor_remote_config(const char *var, const char *value,
154 if (!r)
155 return 0;
156
157 + FREE_AND_NULL(r->partial_clone_filter);
158 return git_config_string(&r->partial_clone_filter, var, value);
159 }
160
@@ -189,6 +190,7 @@ void promisor_remote_clear(struct promisor_remote_config *config)
190 {
191 while (config->promisors) {
192 struct promisor_remote *r = config->promisors;
193 + free(r->partial_clone_filter);
194 config->promisors = config->promisors->next;
195 free(r);
196 }
t/t7814-grep-recurse-submodules.sh
+1
@@ -7,6 +7,7 @@ submodules.
7 '
8
9 TEST_CREATE_REPO_NO_TEMPLATE=1
10 +TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
12
13 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1