push: free_refs() the "local_refs" in set_refspecs()

Fix a memory leak that's been with us since this code was added in ca02465b413 (push: use remote.$name.push as a refmap, 2013-12-03). The "remote = remote_get(...)" added in the same commit would seem to leak based only on the context here, but that function is a wrapper for sticking the remotes we fetch into "the_repository->remote_state". See fd3cb0501e1 (remote: move static variables into per-repository struct, 2021-11-17) for the addition of code in repository.c that free's the "remote" allocated here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 7, 2023 at 00:07 UTC c65d18cb5259079f44c055c07bf46c13c75780c1
14 files changed +21
builtin/push.c
+1
@@ -134,6 +134,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
134 } else
135 refspec_append(&rs, ref);
136 }
137 + free_refs(local_refs);
138 }
139
140 static int push_url_of_remote(struct remote *remote, const char ***url_p)
t/t1416-ref-transaction-hooks.sh
+1
@@ -5,6 +5,7 @@ test_description='reference transaction hooks'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 test_expect_success setup '
t/t2402-worktree-list.sh
+1
@@ -5,6 +5,7 @@ test_description='test git worktree list'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 test_expect_success 'setup' '
t/t5504-fetch-receive-strict.sh
+1
@@ -4,6 +4,7 @@ test_description='fetch/receive strict mode'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 +TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success 'setup and inject "corrupt or missing" object' '
t/t5523-push-upstream.sh
+1
@@ -4,6 +4,7 @@ test_description='push with --set-upstream'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 +TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-terminal.sh
10
t/t5529-push-errors.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='detect some push errors early (before contacting remote)'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup commits' '
t/t5546-receive-limits.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='check receive input limits'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # Let's run tests with different unpack limits: 1 and 10000
t/t5547-push-quarantine.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='check quarantine of objects during push'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'create picky dest repo' '
t/t5606-clone-options.sh
+1
@@ -4,6 +4,7 @@ test_description='basic clone options'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 +TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
t/t5810-proto-disable-local.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='test disabling of local paths in clone/fetch'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY/lib-proto-disable.sh"
8
t/t5813-proto-disable-ssh.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='test disabling of git-over-ssh in clone/fetch'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY/lib-proto-disable.sh"
8
t/t7409-submodule-detached-work-tree.sh
+1
@@ -13,6 +13,7 @@ TEST_NO_CREATE_REPO=1
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15
16 +TEST_PASSES_SANITIZE_LEAK=true
17 . ./test-lib.sh
18
19 test_expect_success 'setup' '
t/t7416-submodule-dash-url.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='check handling of disallowed .gitmodule urls'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t7450-bad-git-dotfiles.sh
+2
@@ -12,6 +12,8 @@ Such as:
12
13 - symlinked .gitmodules, etc
14 '
15 +
16 +TEST_PASSES_SANITIZE_LEAK=true
17 . ./test-lib.sh
18 . "$TEST_DIRECTORY"/lib-pack.sh
19