Skip to content

Commit ce01f92

Browse files
pks-tgitster
authored andcommitted
remote: plug memory leak when aliasing URLs
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90b801d commit ce01f92

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

remote.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static void alias_all_urls(struct remote_state *remote_state)
499499
if (alias)
500500
strvec_replace(&remote_state->remotes[i]->pushurl,
501501
j, alias);
502+
free(alias);
502503
}
503504
add_pushurl_aliases = remote_state->remotes[i]->pushurl.nr == 0;
504505
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)
512513
if (alias)
513514
strvec_replace(&remote_state->remotes[i]->url,
514515
j, alias);
516+
free(alias);
515517
}
516518
}
517519
}

t/t0210-trace2-normal.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
test_description='test trace2 facility (normal target)'
44

5-
TEST_PASSES_SANITIZE_LEAK=false
5+
TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77

88
# Turn off any inherited trace2 settings for this test.

0 commit comments

Comments
 (0)