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 14d30cdfc04 (ref-filter: fix memory leak in `free_array_item()`, 2019-07-10), c514c62a4fd (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 6798b08e848 (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 de004e848a9 (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%2FgFRh6pwrZalY@carlos-mbp.lan/ 2. https://lore.kernel.org/git/87o88obkb1.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Apr 13, 2022 at 22:01 UTC 7a98d9ab00dc0a238b624b20c3884b50fe504e2b
36 files changed +58
revision.c
+10
@@ -2926,6 +2926,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
2926 return left;
2927 }
2928
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 +
2938 static void release_revisions_mailmap(struct string_list *mailmap)
2939 {
2940 if (!mailmap)
@@ -2938,6 +2947,7 @@ void release_revisions(struct rev_info *revs)
2947 {
2948 free_commit_list(revs->commits);
2949 object_array_clear(&revs->pending);
2950 + release_revisions_cmdline(&revs->cmdline);
2951 release_revisions_mailmap(revs->mailmap);
2952 }
2953
t/lib-git-svn.sh
+4
@@ -1,3 +1,7 @@
1 +if test -z "$TEST_FAILS_SANITIZE_LEAK"
2 +then
3 + TEST_PASSES_SANITIZE_LEAK=true
4 +fi
5 . ./test-lib.sh
6
7 if test -n "$NO_SVN_TESTS"
t/t0062-revision-walking.sh
+1
@@ -5,6 +5,7 @@
5
6 test_description='Test revision walking api'
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 cat >run_twice_expected <<-EOF
t/t0101-at-syntax.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='various @{whatever} syntax tests'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t1060-object-corruption.sh
+1
@@ -1,6 +1,7 @@
1 #!/bin/sh
2
3 test_description='see how we handle various forms of corruption'
4 +
5 . ./test-lib.sh
6
7 # convert "1234abcd" to ".git/objects/12/34abcd"
t/t3303-notes-subtrees.sh
+1
@@ -5,6 +5,7 @@ test_description='Test commit notes organized in subtrees'
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 number_of_commits=100
t/t3305-notes-fanout.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 path_has_fanout() {
t/t3408-rebase-multi-line.sh
+1
@@ -5,6 +5,7 @@ test_description='rebasing a commit with multi-line first paragraph.'
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/t4027-diff-submodule.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='difference in submodules'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff.sh
8
t/t4128-apply-root.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='apply same filename'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t4212-log-corrupt.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='git log with invalid commit headers'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t5515-fetch-merge-logic.sh
+1
@@ -14,6 +14,7 @@ export GIT_TEST_PROTOCOL_VERSION
14 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
15 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16
17 +TEST_PASSES_SANITIZE_LEAK=true
18 . ./test-lib.sh
19
20 build_script () {
t/t5518-fetch-exit-status.sh
+1
@@ -8,6 +8,7 @@ test_description='fetch exit status test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 +TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13
14 test_expect_success setup '
t/t6002-rev-list-bisect.sh
+1
@@ -4,6 +4,7 @@
4 #
5 test_description='Tests git rev-list --bisect functionality'
6
7 +TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions
10
t/t6003-rev-list-topo-order.sh
+1
@@ -5,6 +5,7 @@
5
6 test_description='Tests git rev-list --topo-order functionality'
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions
11
t/t6005-rev-list-count.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='git rev-list --max-count and --skip test'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t6018-rev-list-glob.sh
+1
@@ -5,6 +5,7 @@ test_description='rev-list/rev-parse --glob'
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 commit () {
t/t6100-rev-list-in-order.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='rev-list testing in-commit-order'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup a commit history with trees, blobs' '
t/t9100-git-svn-basic.sh
+1
@@ -8,6 +8,7 @@ test_description='git svn basic tests'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 +TEST_FAILS_SANITIZE_LEAK=true
12 . ./lib-git-svn.sh
13
14 prepare_utf8_locale
t/t9101-git-svn-props.sh
+2
@@ -4,6 +4,8 @@
4 #
5
6 test_description='git svn property tests'
7 +
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 mkdir import
t/t9104-git-svn-follow-parent.sh
+2
@@ -4,6 +4,8 @@
4 #
5
6 test_description='git svn fetching'
7 +
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'initialize repo' '
t/t9106-git-svn-commit-diff-clobber.sh
+2
@@ -2,6 +2,8 @@
2 #
3 # Copyright (c) 2006 Eric Wong
4 test_description='git svn commit-diff clobber'
5 +
6 +TEST_FAILS_SANITIZE_LEAK=true
7 . ./lib-git-svn.sh
8
9 test_expect_success 'initialize repo' '
t/t9115-git-svn-dcommit-funky-renames.sh
+1
@@ -5,6 +5,7 @@
5
6 test_description='git svn dcommit can commit renames of files with ugly names'
7
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'load repository with strange names' '
t/t9116-git-svn-log.sh
+2
@@ -4,6 +4,8 @@
4 #
5
6 test_description='git svn log tests'
7 +
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'setup repository and import' '
t/t9122-git-svn-author.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='git svn authorship'
4 +
5 +TEST_FAILS_SANITIZE_LEAK=true
6 . ./lib-git-svn.sh
7
8 test_expect_success 'setup svn repository' '
t/t9127-git-svn-partial-rebuild.sh
+2
@@ -4,6 +4,8 @@
4 #
5
6 test_description='git svn partial-rebuild tests'
7 +
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'initialize svnrepo' '
t/t9129-git-svn-i18n-commitencoding.sh
+1
@@ -4,6 +4,7 @@
4
5 test_description='git svn honors i18n.commitEncoding in config'
6
7 +TEST_FAILS_SANITIZE_LEAK=true
8 . ./lib-git-svn.sh
9
10 compare_git_head_with () {
t/t9132-git-svn-broken-symlink.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='test that git handles an svn repository with empty symlinks'
4
5 +TEST_FAILS_SANITIZE_LEAK=true
6 . ./lib-git-svn.sh
7 test_expect_success 'load svn dumpfile' '
8 svnadmin load "$rawsvnrepo" <<EOF
t/t9139-git-svn-non-utf8-commitencoding.sh
+1
@@ -4,6 +4,7 @@
4
5 test_description='git svn refuses to dcommit non-UTF8 messages'
6
7 +TEST_FAILS_SANITIZE_LEAK=true
8 . ./lib-git-svn.sh
9
10 # ISO-2022-JP can pass for valid UTF-8, so skipping that in this test
t/t9146-git-svn-empty-dirs.sh
+2
@@ -3,6 +3,8 @@
3 # Copyright (c) 2009 Eric Wong
4
5 test_description='git svn creates empty directories'
6 +
7 +TEST_FAILS_SANITIZE_LEAK=true
8 . ./lib-git-svn.sh
9
10 test_expect_success 'initialize repo' '
t/t9148-git-svn-propset.sh
+1
@@ -5,6 +5,7 @@
5
6 test_description='git svn propset tests'
7
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'setup propset via import' '
t/t9151-svn-mergeinfo.sh
+1
@@ -5,6 +5,7 @@
5
6 test_description='git-svn svn mergeinfo properties'
7
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 test_expect_success 'load svn dump' "
t/t9160-git-svn-preserve-empty-dirs.sh
+1
@@ -9,6 +9,7 @@ This test uses git to clone a Subversion repository that contains empty
9 directories, and checks that corresponding directories are created in the
10 local Git repository with placeholder files.'
11
12 +TEST_FAILS_SANITIZE_LEAK=true
13 . ./lib-git-svn.sh
14
15 GIT_REPO=git-svn-repo
t/t9162-git-svn-dcommit-interactive.sh
+2
@@ -3,6 +3,8 @@
3 # Copyright (c) 2011 Frédéric Heitzmann
4
5 test_description='git svn dcommit --interactive series'
6 +
7 +TEST_FAILS_SANITIZE_LEAK=true
8 . ./lib-git-svn.sh
9
10 test_expect_success 'initialize repo' '
t/t9164-git-svn-dcommit-concurrent.sh
+2
@@ -4,6 +4,8 @@
4 #
5
6 test_description='concurrent git svn dcommit'
7 +
8 +TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11
t/t9501-gitweb-standalone-http-status.sh
+1
@@ -13,6 +13,7 @@ code and message.'
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15
16 +TEST_PASSES_SANITIZE_LEAK=true
17 . ./lib-gitweb.sh
18
19 #