]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revisions API: have release_revisions() release "cmdline"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 13 Apr 2022 20:01:47 +0000 (22:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Apr 2022 06:56:09 +0000 (23:56 -0700)
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>
36 files changed:
revision.c
t/lib-git-svn.sh
t/t0062-revision-walking.sh
t/t0101-at-syntax.sh
t/t1060-object-corruption.sh
t/t3303-notes-subtrees.sh
t/t3305-notes-fanout.sh
t/t3408-rebase-multi-line.sh
t/t4027-diff-submodule.sh
t/t4128-apply-root.sh
t/t4212-log-corrupt.sh
t/t5515-fetch-merge-logic.sh
t/t5518-fetch-exit-status.sh
t/t6002-rev-list-bisect.sh
t/t6003-rev-list-topo-order.sh
t/t6005-rev-list-count.sh
t/t6018-rev-list-glob.sh
t/t6100-rev-list-in-order.sh
t/t9100-git-svn-basic.sh
t/t9101-git-svn-props.sh
t/t9104-git-svn-follow-parent.sh
t/t9106-git-svn-commit-diff-clobber.sh
t/t9115-git-svn-dcommit-funky-renames.sh
t/t9116-git-svn-log.sh
t/t9122-git-svn-author.sh
t/t9127-git-svn-partial-rebuild.sh
t/t9129-git-svn-i18n-commitencoding.sh
t/t9132-git-svn-broken-symlink.sh
t/t9139-git-svn-non-utf8-commitencoding.sh
t/t9146-git-svn-empty-dirs.sh
t/t9148-git-svn-propset.sh
t/t9151-svn-mergeinfo.sh
t/t9160-git-svn-preserve-empty-dirs.sh
t/t9162-git-svn-dcommit-interactive.sh
t/t9164-git-svn-dcommit-concurrent.sh
t/t9501-gitweb-standalone-http-status.sh

index 622f0faecc4ccc8ee16d9219b87cdd03afbb895c..de4076e77de1beb0db139513034174ca5ec222ea 100644 (file)
@@ -2926,6 +2926,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
        return left;
 }
 
+static void release_revisions_cmdline(struct rev_cmdline_info *cmdline)
+{
+       unsigned int i;
+
+       for (i = 0; i < cmdline->nr; i++)
+               free((char *)cmdline->rev[i].name);
+       free(cmdline->rev);
+}
+
 static void release_revisions_mailmap(struct string_list *mailmap)
 {
        if (!mailmap)
@@ -2938,6 +2947,7 @@ void release_revisions(struct rev_info *revs)
 {
        free_commit_list(revs->commits);
        object_array_clear(&revs->pending);
+       release_revisions_cmdline(&revs->cmdline);
        release_revisions_mailmap(revs->mailmap);
 }
 
index 2fde2353fd38356548fd40e4808984618b0d9585..ea28971e8ee6abfcd3c0394c6d8b143c75ac12dd 100644 (file)
@@ -1,3 +1,7 @@
+if test -z "$TEST_FAILS_SANITIZE_LEAK"
+then
+       TEST_PASSES_SANITIZE_LEAK=true
+fi
 . ./test-lib.sh
 
 if test -n "$NO_SVN_TESTS"
index 8e215867b8c197dedef32c569e1d1f632d22b631..b9480c8178193e4eba46dd2d581e1aa4eaa5dae6 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='Test revision walking api'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 cat >run_twice_expected <<-EOF
index a1998b558f96bb956b4ddce500d9447ded49a54d..878aadd64c9517dc1891031bd8bee0b298cfccb6 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='various @{whatever} syntax tests'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index bc89371f53436dbf3427f231f560ef1b1f8683f6..e8a58b1589775d82e7005c86cadb7a4fea10d61e 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 test_description='see how we handle various forms of corruption'
+
 . ./test-lib.sh
 
 # convert "1234abcd" to ".git/objects/12/34abcd"
index eac193757bf1a5cd27ed4d54249a41de7b302bde..bc9b791d1b9ed2a780de4544232f769e093072b1 100755 (executable)
@@ -5,6 +5,7 @@ test_description='Test commit notes organized in subtrees'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 number_of_commits=100
index 9976d787f4721c898d52eb0211399b145c9e1872..64a9915761a82a6ea8d640dabfe3811db6450a5a 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 path_has_fanout() {
index cde3562e3a64f756544763107d9c607eaa4f38ca..7b4607d72f2748df9d0800a5e471e4af1d6ae32a 100755 (executable)
@@ -5,6 +5,7 @@ test_description='rebasing a commit with multi-line first paragraph.'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
index 295da987cce5c8141b96d35944b73fb3f86f7e64..40164ae07d2c06d9ef5fc67b16e5ad8421b2875e 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='difference in submodules'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-diff.sh
 
index f6db5a79dd9d356c93a935374c4c27520ecf6593..ed94c90204e9c2eab135a1c2dcdeb15cf33e214c 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='apply same filename'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 0244888a5a7a8939276b0425b9144a8e262a2c8f..30a219894bb45f2655596fe02e8a7d001a35eabd 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='git log with invalid commit headers'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 320d26796d24d8a2281d37220a7bdf73cafaa503..c100a809c5e59f0b48d8b616883c1397de027ff3 100755 (executable)
@@ -14,6 +14,7 @@ export GIT_TEST_PROTOCOL_VERSION
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 build_script () {
index 5c4ac2556e7820f41285b5f653a5f61cc5f75846..c13120088fa684b59cc2f598d8ebfe05cae7b42c 100755 (executable)
@@ -8,6 +8,7 @@ test_description='fetch exit status test'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
index b95a0212adff71632d0b91cf96432b276c86a44c..162cf50778d6191f71941b0f6c9ef600c6a10684 100755 (executable)
@@ -4,6 +4,7 @@
 #
 test_description='Tests git rev-list --bisect functionality'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions
 
index 24d1836f417d67a224f0d9bef619952a39ed28eb..1f7d7dd20c1cf129c8a98ba59694f75e8e0de911 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='Tests git rev-list --topo-order functionality'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions
 
index e960049f647cfca4a18defaba7dde9d43c8f94ef..0729f800c3c95790946d68296240799c2dbbb5ad 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='git rev-list --max-count and --skip test'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 24b34add833468dd73136689980e4ca3a051411b..e1abc5c2b32f57526c277e6ac62fa1b45f2f46bd 100755 (executable)
@@ -5,6 +5,7 @@ test_description='rev-list/rev-parse --glob'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 commit () {
index e934bc239c534d5da532c28d520732475859b665..88ed7bd75a75f0d8eb730d2f3db7dc59afe7807f 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='rev-list testing in-commit-order'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup a commit history with trees, blobs' '
index fea41b3c3606df1fc6d8111cdd74522532ca8b0b..7c5b847f58424dc62c330674971d2d849f77ac4e 100755 (executable)
@@ -8,6 +8,7 @@ test_description='git svn basic tests'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 prepare_utf8_locale
index 8b5681dd68ab05adc504437a54ff2877ed180516..d043e80fc349f85e1cd4168c9bf4d343dfeee0d5 100755 (executable)
@@ -4,6 +4,8 @@
 #
 
 test_description='git svn property tests'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 mkdir import
index c7d8e0bf00f6344d1216f117f57587cda3116fc2..5cf2ef4b8b0fc3a9a587baea4e8421893c90bd14 100755 (executable)
@@ -4,6 +4,8 @@
 #
 
 test_description='git svn fetching'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'initialize repo' '
index aec45bca3b7b6fc4561e02ff975f77a5331cb7ce..3cab0b9720a6544ade5caf91a3f678ad577cc3b0 100755 (executable)
@@ -2,6 +2,8 @@
 #
 # Copyright (c) 2006 Eric Wong
 test_description='git svn commit-diff clobber'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'initialize repo' '
index 743fbe1fe46929583aacacc60ba959c38d8a2f09..419f055721dbc32122e9d595d691c77bb8a24212 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='git svn dcommit can commit renames of files with ugly names'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'load repository with strange names' '
index 0a9f1ef366db07c31668f6bf4cf0d9267d788453..34f6c80dea3d3c508ca549d6a576e9cc634e0884 100755 (executable)
@@ -4,6 +4,8 @@
 #
 
 test_description='git svn log tests'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'setup repository and import' '
index 9e8fe38e7ef94b7343122b279c94c250dcf48756..527ba3d29322a14d609ea57e3740672f144f3182 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='git svn authorship'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'setup svn repository' '
index 2e4789d061fe084024b621708ee27e629c2a004a..90b1b30dde5b96383ec7f66dc3848ef7cd2fb7b1 100755 (executable)
@@ -4,6 +4,8 @@
 #
 
 test_description='git svn partial-rebuild tests'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'initialize svnrepo' '
index 01e1e8a8f76765d081270d37a980778fad4189d0..185248a4cd766172969ad88f7dcd94258733f644 100755 (executable)
@@ -4,6 +4,7 @@
 
 test_description='git svn honors i18n.commitEncoding in config'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 compare_git_head_with () {
index aeceffaf7b0824b8da673261f523589d3b141619..4d8d0584b795d21fab8ba7dcbd47b50c178c2757 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='test that git handles an svn repository with empty symlinks'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 test_expect_success 'load svn dumpfile' '
        svnadmin load "$rawsvnrepo" <<EOF
index 22d80b0be2b94515132a79401b719f98794f4616..b7f756b2b7f28f6e5d32fa595ebbf1ca2bebb45b 100755 (executable)
@@ -4,6 +4,7 @@
 
 test_description='git svn refuses to dcommit non-UTF8 messages'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 # ISO-2022-JP can pass for valid UTF-8, so skipping that in this test
index 80cb55fee70e2affd719c0b6812e01f3125ce42e..79c26ed69c16cad42a32a555bb33635a154441e7 100755 (executable)
@@ -3,6 +3,8 @@
 # Copyright (c) 2009 Eric Wong
 
 test_description='git svn creates empty directories'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'initialize repo' '
index aebb28995e50a0a589e8fff33997d9816de1fdb2..6cc76a07b39a90d590759bbb7033da3953969092 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='git svn propset tests'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'setup propset via import' '
index c93a5beab25703a935e22d012420e044a8c0ed8e..85221d439bd516d6e7574975ae696981c6e73b3b 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='git-svn svn mergeinfo properties'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'load svn dump' "
index 36c6b1a12ffd95a1d6fe4ee4efd18a47f1581078..9cf7a1427ab081f2084b147b7dc4b1e3aa0f1005 100755 (executable)
@@ -9,6 +9,7 @@ This test uses git to clone a Subversion repository that contains empty
 directories, and checks that corresponding directories are created in the
 local Git repository with placeholder files.'
 
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 GIT_REPO=git-svn-repo
index e38d9fa37b50195607b0f1d066eb4c78f39cfc4f..e2aa8ed88a96ec0b50fb33f31e2e6d232895067c 100755 (executable)
@@ -3,6 +3,8 @@
 # Copyright (c) 2011 Frédéric Heitzmann
 
 test_description='git svn dcommit --interactive series'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 test_expect_success 'initialize repo' '
index 8466269bf50b66dd8d55cadc891600172659438e..1465156072e32a75fb759784e65f9f7e2ca4c84a 100755 (executable)
@@ -4,6 +4,8 @@
 #
 
 test_description='concurrent git svn dcommit'
+
+TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 
index 32814e75df5b0d796b292c2ac39d370c636e5e67..c900231079cf750f0f1111ca74ddca7803becf6c 100755 (executable)
@@ -13,6 +13,7 @@ code and message.'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./lib-gitweb.sh
 
 #