]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: plug memory leak when aliasing URLs
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:51:52 +0000 (08:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:07:56 +0000 (10:07 -0700)
When we have a `url.*.insteadOf` configuration, then we end up aliasing
URLs when populating remotes. One place where this happens is in
`alias_all_urls()`, where we loop through all remotes and then alias
each of their URLs. The actual aliasing logic is then contained in
`alias_url()`, which returns an allocated string that contains the new
URL. This URL replaces the old URL that we have in the strvec that
contains all remote URLs.

We replace the remote URLs via `strvec_replace()`, which does not hand
over ownership of the new string to the vector. Still, we didn't free
the aliased URL and thus have a memory leak here. Fix it by freeing the
aliased string.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
t/t0210-trace2-normal.sh

index f43cf5e7a4d2432113400c28a45e58cc2230b36b..3b898edd23a3c3afd08535c690f88334e06732d6 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -499,6 +499,7 @@ static void alias_all_urls(struct remote_state *remote_state)
                        if (alias)
                                strvec_replace(&remote_state->remotes[i]->pushurl,
                                               j, alias);
+                       free(alias);
                }
                add_pushurl_aliases = remote_state->remotes[i]->pushurl.nr == 0;
                for (j = 0; j < remote_state->remotes[i]->url.nr; j++) {
@@ -512,6 +513,7 @@ static void alias_all_urls(struct remote_state *remote_state)
                        if (alias)
                                strvec_replace(&remote_state->remotes[i]->url,
                                               j, alias);
+                       free(alias);
                }
        }
 }
index c312657a12cd34334ce58361c7f0a73f384daff6..b9adc94aab41650da73e5541bc4666102e4baad5 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='test trace2 facility (normal target)'
 
-TEST_PASSES_SANITIZE_LEAK=false
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # Turn off any inherited trace2 settings for this test.