Skip to content

Commit 7a98d9a

Browse files
avargitster
authored andcommitted
revisions API: have release_revisions() release "cmdline"
Extend the the release_revisions() function so that it frees the "cmdline" in the "struct rev_info". This in combination with a preceding change to free "commits" and "mailmap" means that we can whitelist another test under "TEST_PASSES_SANITIZE_LEAK=true". There was a proposal in [1] to do away with xstrdup()-ing this add_rev_cmdline(), perhaps that would be worthwhile, but for now let's just free() it. We could also make that a "char *" in "struct rev_cmdline_entry" itself, but since we own it let's expose it as a constant to outside callers. I proposed that in [2] but have since changed my mind. See 14d30cd (ref-filter: fix memory leak in `free_array_item()`, 2019-07-10), c514c62 (checkout: fix leak of non-existent branch names, 2020-08-14) and other log history hits for "free((char *)" for prior art. This includes the tests we had false-positive passes on before my 6798b08 (perl Git.pm: don't ignore signalled failure in _cmd_close(), 2022-02-01), now they pass for real. Since there are 66 tests matching t/t[0-9]*git-svn*.sh it's easier to list those that don't pass than to touch most of those 66. So let's introduce a "TEST_FAILS_SANITIZE_LEAK=true", which if set in the tests won't cause lib-git-svn.sh to set "TEST_PASSES_SANITIZE_LEAK=true. This change also marks all the tests that we removed "TEST_FAILS_SANITIZE_LEAK=true" from in an earlier commit due to removing the UNLEAK() from cmd_format_patch(), we can now assert that its API use doesn't leak any "struct rev_info" memory. This change also made commit "t5503-tagfollow.sh" pass on current master, but that would regress when combined with ps/fetch-atomic-fixup's de004e8 (t5503: simplify setup of test which exercises failure of backfill, 2022-03-03) (through no fault of that topic, that change started using "git clone" in the test, which has an outstanding leak). Let's leave that test out for now to avoid in-flight semantic conflicts. 1. https://lore.kernel.org/git/YUj%[email protected]/ 2. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a52f07a commit 7a98d9a

36 files changed

+58
-0
lines changed

revision.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
29262926
return left;
29272927
}
29282928

2929+
static void release_revisions_cmdline(struct rev_cmdline_info *cmdline)
2930+
{
2931+
unsigned int i;
2932+
2933+
for (i = 0; i < cmdline->nr; i++)
2934+
free((char *)cmdline->rev[i].name);
2935+
free(cmdline->rev);
2936+
}
2937+
29292938
static void release_revisions_mailmap(struct string_list *mailmap)
29302939
{
29312940
if (!mailmap)
@@ -2938,6 +2947,7 @@ void release_revisions(struct rev_info *revs)
29382947
{
29392948
free_commit_list(revs->commits);
29402949
object_array_clear(&revs->pending);
2950+
release_revisions_cmdline(&revs->cmdline);
29412951
release_revisions_mailmap(revs->mailmap);
29422952
}
29432953

t/lib-git-svn.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if test -z "$TEST_FAILS_SANITIZE_LEAK"
2+
then
3+
TEST_PASSES_SANITIZE_LEAK=true
4+
fi
15
. ./test-lib.sh
26

37
if test -n "$NO_SVN_TESTS"

t/t0062-revision-walking.sh

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

66
test_description='Test revision walking api'
77

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

1011
cat >run_twice_expected <<-EOF

t/t0101-at-syntax.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='various @{whatever} syntax tests'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'setup' '

t/t1060-object-corruption.sh

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

33
test_description='see how we handle various forms of corruption'
4+
45
. ./test-lib.sh
56

67
# convert "1234abcd" to ".git/objects/12/34abcd"

t/t3303-notes-subtrees.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='Test commit notes organized in subtrees'
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
number_of_commits=100

t/t3305-notes-fanout.sh

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

33
test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
44

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

78
path_has_fanout() {

t/t3408-rebase-multi-line.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='rebasing a commit with multi-line first paragraph.'
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/t4027-diff-submodule.sh

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

33
test_description='difference in submodules'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67
. "$TEST_DIRECTORY"/lib-diff.sh
78

t/t4128-apply-root.sh

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

33
test_description='apply same filename'
44

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

78
test_expect_success 'setup' '

0 commit comments

Comments
 (0)