Skip to content

Commit 1fdd31c

Browse files
avargitster
authored andcommitted
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. 575f497 (Add first cut at "git-receive-pack", 2005-06-29) 2. eb1af2d (git-receive-pack: start parsing ref update commands, 2005-06-29) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb2ebe7 commit 1fdd31c

10 files changed

+22
-0
lines changed

builtin/receive-pack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,16 @@ static struct command **queue_command(struct command **tail,
20322032
return &cmd->next;
20332033
}
20342034

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+
20352045
static void queue_commands_from_cert(struct command **tail,
20362046
struct strbuf *push_cert)
20372047
{
@@ -2569,6 +2579,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
25692579
run_receive_hook(commands, "post-receive", 1,
25702580
&push_options);
25712581
run_update_post_hook(commands);
2582+
free_commands(commands);
25722583
string_list_clear(&push_options, 0);
25732584
if (auto_gc) {
25742585
struct child_process proc = CHILD_PROCESS_INIT;

t/t5405-send-pack-rewind.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='forced push to replace commit we do not have'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success setup '

t/t5406-remote-rejects.sh

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

33
test_description='remote push rejects are reported by client'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup' '

t/t5507-remote-environment.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='check environment showed to remote side of transports'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'set up "remote" push situation' '

t/t5522-pull-symlink.sh

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

33
test_description='pulling from symlinked subdir'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
# The scenario we are building:

t/t5527-fetch-odd-refs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test fetching of oddly-named refs'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
# afterwards we will have:

t/t5560-http-backend-noserver.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test git-http-backend-noserver'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"

t/t5561-http-backend.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test git-http-backend'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89
. "$TEST_DIRECTORY"/lib-httpd.sh
910

t/t5562-http-backend-content-length.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='test git-http-backend respects CONTENT_LENGTH'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_lazy_prereq GZIP 'gzip --version'

t/t5705-session-id-in-capabilities.sh

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

33
test_description='session ID in capabilities'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
REPO="$(pwd)/repo"

0 commit comments

Comments
 (0)