git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 22/23] revision: fix leaking parents when simplifying commits
Date: Mon, 16 Sep 2024 13:46:28 +0200	[thread overview]
Message-ID: <2a23df9a6869f58a231cfe4947b322690d48cb1a.1726484308.git.ps@pks.im> (raw)
In-Reply-To: <cover.1726484308.git.ps@pks.im>

When simplifying commits, e.g. because they are treesame with their
parents, we unset the commit's parent pointers but never free them. Plug
the resulting memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 revision.c                        | 5 +++++
 t/t1414-reflog-walk.sh            | 1 +
 t/t5310-pack-bitmaps.sh           | 1 +
 t/t5326-multi-pack-bitmaps.sh     | 2 ++
 t/t6004-rev-list-path-optim.sh    | 1 +
 t/t6019-rev-list-ancestry-path.sh | 1 +
 t/t6111-rev-list-treesame.sh      | 1 +
 7 files changed, 12 insertions(+)

diff --git a/revision.c b/revision.c
index 2d7ad2bddff..e79f39e5555 100644
--- a/revision.c
+++ b/revision.c
@@ -1071,7 +1071,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
 					ts->treesame[nth_parent] = 1;
 				continue;
 			}
+
+			free_commit_list(parent->next);
 			parent->next = NULL;
+			while (commit->parents != parent)
+				pop_commit(&commit->parents);
 			commit->parents = parent;
 
 			/*
@@ -1103,6 +1107,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
 					die("cannot simplify commit %s (invalid %s)",
 					    oid_to_hex(&commit->object.oid),
 					    oid_to_hex(&p->object.oid));
+				free_commit_list(p->parents);
 				p->parents = NULL;
 			}
 		/* fallthrough */
diff --git a/t/t1414-reflog-walk.sh b/t/t1414-reflog-walk.sh
index be6c3f472c1..49d28166da0 100755
--- a/t/t1414-reflog-walk.sh
+++ b/t/t1414-reflog-walk.sh
@@ -4,6 +4,7 @@ test_description='various tests of reflog walk (log -g) behavior'
 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 'set up some reflog entries' '
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index a6de7c57643..7044c7d7c6d 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -2,6 +2,7 @@
 
 test_description='exercise basic bitmap functionality'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-bitmap.sh
 
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index 832b92619c0..6eaa692f33b 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='exercise basic multi-pack bitmap functionality'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "${TEST_DIRECTORY}/lib-bitmap.sh"
 
diff --git a/t/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh
index cd4f420e2a1..5416241edea 100755
--- a/t/t6004-rev-list-path-optim.sh
+++ b/t/t6004-rev-list-path-optim.sh
@@ -16,6 +16,7 @@ test_description='git rev-list trivial path optimization 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 '
diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh
index 738da23628b..1aabab69568 100755
--- a/t/t6019-rev-list-ancestry-path.sh
+++ b/t/t6019-rev-list-ancestry-path.sh
@@ -29,6 +29,7 @@ test_description='--ancestry-path'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_merge () {
diff --git a/t/t6111-rev-list-treesame.sh b/t/t6111-rev-list-treesame.sh
index 90ff1416400..f63bc8d3da6 100755
--- a/t/t6111-rev-list-treesame.sh
+++ b/t/t6111-rev-list-treesame.sh
@@ -16,6 +16,7 @@ test_description='TREESAME and limiting'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 note () {
-- 
2.46.0.551.gc5ee8f2d1c.dirty


  parent reply	other threads:[~2024-09-16 11:46 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 11:45 [PATCH 00/23] Memory leak fixes (pt.7) Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-16 16:24   ` Justin Tobler
2024-09-16 11:45 ` [PATCH 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-16 18:51   ` Justin Tobler
2024-09-17 10:19     ` Patrick Steinhardt
2024-09-25 20:26       ` Junio C Hamano
2024-09-26 11:58         ` Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-20 16:43   ` Junio C Hamano
2024-09-16 11:45 ` [PATCH 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-20 17:00   ` Junio C Hamano
2024-09-24  7:20     ` Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-20 17:21   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 14/23] builtin/repack: fix leaking configuration Patrick Steinhardt
2024-09-20 17:28   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-20 17:59   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-16 11:46 ` Patrick Steinhardt [this message]
2024-09-19 17:17   ` [PATCH 22/23] revision: fix leaking parents when simplifying commits Junio C Hamano
2024-09-16 11:46 ` [PATCH 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt
2024-09-19 18:54 ` [PATCH 00/23] Memory leak fixes (pt.7) Junio C Hamano
2024-09-24  7:20   ` Patrick Steinhardt
2024-09-26 11:45 ` [PATCH v2 " Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 14/23] builtin/repack: fix leaking configuration Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 22/23] revision: fix leaking parents when simplifying commits Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a23df9a6869f58a231cfe4947b322690d48cb1a.1726484308.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).