receive-pack: release the linked "struct command *" list

Fix a memory leak that's been with us since this code was introduced in [1]. Later in [2] we started using FLEX_ALLOC_MEM() to allocate the "struct command *". 1. 575f497456e (Add first cut at "git-receive-pack", 2005-06-29) 2. eb1af2df0b1 (git-receive-pack: start parsing ref update commands, 2005-06-29) 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 1fdd31cf52a242c3b73b4093a68a30123c5c7549
10 files changed +22
builtin/receive-pack.c
+11
@@ -2032,6 +2032,16 @@ static struct command **queue_command(struct command **tail,
2032 return &cmd->next;
2033 }
2034
2035 +static void free_commands(struct command *commands)
2036 +{
2037 + while (commands) {
2038 + struct command *next = commands->next;
2039 +
2040 + free(commands);
2041 + commands = next;
2042 + }
2043 +}
2044 +
2045 static void queue_commands_from_cert(struct command **tail,
2046 struct strbuf *push_cert)
2047 {
@@ -2569,6 +2579,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
2579 run_receive_hook(commands, "post-receive", 1,
2580 &push_options);
2581 run_update_post_hook(commands);
2582 + free_commands(commands);
2583 string_list_clear(&push_options, 0);
2584 if (auto_gc) {
2585 struct child_process proc = CHILD_PROCESS_INIT;
t/t5405-send-pack-rewind.sh
+1
@@ -5,6 +5,7 @@ test_description='forced push to replace commit we do not have'
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/t5406-remote-rejects.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='remote push rejects are reported by client'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t5507-remote-environment.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='check environment showed to remote side of transports'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'set up "remote" push situation' '
t/t5522-pull-symlink.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='pulling from symlinked subdir'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # The scenario we are building:
t/t5527-fetch-odd-refs.sh
+1
@@ -4,6 +4,7 @@ test_description='test fetching of oddly-named refs'
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 # afterwards we will have:
t/t5560-http-backend-noserver.sh
+1
@@ -4,6 +4,7 @@ test_description='test git-http-backend-noserver'
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 HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
t/t5561-http-backend.sh
+1
@@ -4,6 +4,7 @@ test_description='test git-http-backend'
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-httpd.sh
10
t/t5562-http-backend-content-length.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='test git-http-backend respects CONTENT_LENGTH'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_lazy_prereq GZIP 'gzip --version'
t/t5705-session-id-in-capabilities.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='session ID in capabilities'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 REPO="$(pwd)/repo"