some commit-graph leak fixes
cover some commit-graph leak fixes
I noticed while working on the jk/commit-graph-verify-fix topic that free_commit_graph() leaks any slices of a commit-graph-chain except for the first. I naively hoped that fixing that would make t5324 leak-free, but it turns out there were a number of other leaks, so I fixed those, too. A couple of them were in the merge code, which in turn means a bunch of new test scripts are now leak-free.
Even though I saw the problem on that other topic, there's no dependency here; this series can be applied directly to master (or possibly even maint, though I didn't try).
[01/10]: t6700: mark test as leak-free
[02/10]: commit-reach: free temporary list in get_octopus_merge_bases() [03/10]: merge: free result of repo_get_merge_bases()
[04/10]: commit-graph: move slab-clearing to close_commit_graph() [05/10]: commit-graph: free all elements of graph chain [06/10]: commit-graph: delay base_graph assignment in add_graph_to_chain() [07/10]: commit-graph: free graph struct that was not added to chain [08/10]: commit-graph: free write-context entries before overwriting [09/10]: commit-graph: free write-context base_graph_name during cleanup [10/10]: commit-graph: clear oidset after finishing write
builtin/commit-graph.c | 1 + builtin/merge.c | 5 +++- commit-graph.c | 40 ++++++++++++++---------------- commit-reach.c | 1 + t/t4214-log-graph-octopus.sh | 1 + t/t4215-log-skewed-merges.sh | 1 + t/t5324-split-commit-graph.sh | 2 ++ t/t5328-commit-graph-64bit-time.sh | 2 ++ t/t5521-pull-options.sh | 1 + t/t6009-rev-list-parent.sh | 1 + t/t6416-recursive-corner-cases.sh | 1 + t/t6433-merge-toplevel.sh | 1 + t/t6437-submodule-merge.sh | 1 + t/t6700-tree-depth.sh | 2 ++ t/t7602-merge-octopus-many.sh | 1 + t/t7603-merge-reduce-heads.sh | 1 + t/t7607-merge-state.sh | 1 + t/t7608-merge-messages.sh | 1 + 18 files changed, 42 insertions(+), 22 deletions(-)
-Peff
PATCH 1/10 t6700: mark test as leak-free
This test has never leaked since it was added. Let's annotate it to make sure it stays that way (and to reduce noise when looking for other leak-free scripts after we fix some leaks).
---
Obviously not directly related to the rest; this could be spun off to its own series, or put atop jk/tree-name-and-depth-limit and merged from there.
t/t6700-tree-depth.sh | 2 ++ 1 file changed, 2 insertions(+)
t/t6700-tree-depth.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='handling of deep trees in various commands' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # We'll test against two depths here: a small one that will let us check the
Signature · 1 line
2.42.0.810.gbc538a0ee6
Re: [PATCH 01/10] t6700: mark test as leak-free
Quoted 9 lines · Jeff King
This test has never leaked since it was added. Let's annotate it to make sure it stays that way (and to reduce noise when looking for other leak-free scripts after we fix some leaks).
Signed-off-by Jeff King <[email protected]>---
Obviously not directly related to the rest; this could be spun off to its own series, or put atop jk/tree-name-and-depth-limit and merged from there.
I wondered how I missed this in tb/mark-more-tests-as-leak-free, but the answer is trivial: that topic preceded your tree depth stuff ;-).
This change makes good sense, and I don't think it's worth spinning off into its own series.
Thanks,
Taylor
PATCH 2/10 commit-reach: free temporary list in get_octopus_merge_bases()
In reply to Jeff KingWe loop over the set of commits to merge, and for each one compute the merge base against the existing set of merge base candidates we've found. Then we replace the candidate set with a simple assignment of the list head, leaking the old list. We should free it first before assignment.
This makes t5521 leak-free, so mark it as such.
--- commit-reach.c | 1 + t/t5521-pull-options.sh | 1 + 2 files changed, 2 insertions(+)
commit-reach.c +1 -0
@@ -173,6 +173,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)for (k = bases; k; k = k->next) end = k; } +free_commit_list (ret); ret = new_commits; }return ret;
t/t5521-pull-options.sh +1 -0
@@ -5,6 +5,7 @@ test_description='pull options' 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' '
Signature · 1 line
2.42.0.810.gbc538a0ee6
PATCH 3/10 merge: free result of repo_get_merge_bases()
In reply to Jeff KingWe call repo_get_merge_bases(), which allocates a commit_list, but never free the result, causing a leak.
The obvious solution is to free it, but we need to look at the contents of the first item to decide whether to leave the loop. One option is to free it in both code paths. But since the commit that the list points to is longer-lived than the list itself, we can just dereference it immediately, free the list, and then continue with the existing logic. This is about the same amount of code, but keeps the list management all in one place.
This lets us mark a number of merge-related test scripts as leak-free.
--- builtin/merge.c | 5 ++++- t/t4214-log-graph-octopus.sh | 1 + t/t4215-log-skewed-merges.sh | 1 + t/t6009-rev-list-parent.sh | 1 + t/t6416-recursive-corner-cases.sh | 1 + t/t6433-merge-toplevel.sh | 1 + t/t6437-submodule-merge.sh | 1 + t/t7602-merge-octopus-many.sh | 1 + t/t7603-merge-reduce-heads.sh | 1 + t/t7607-merge-state.sh | 1 + t/t7608-merge-messages.sh | 1 + 11 files changed, 14 insertions(+), 1 deletion(-)
builtin/merge.c +4 -1
@@ -1634,6 +1634,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)for (j = remoteheads; j; j = j->next) {struct commit_list *common_one; +struct commit *common_item;/* * Here we *have* to calculate the individual
@@ -1643,7 +1644,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) common_one =repo_get_merge_bases (the_repository, head_commit, j->item); -if (!oideq (&common_one->item->object.oid, &j->item->object.oid)) { + common_item = common_one->item; +free_commit_list (common_one); +if (!oideq (&common_item->object.oid, &j->item->object.oid)) { up_to_date =0 ;break ; }
t/t4214-log-graph-octopus.sh +1 -0
@@ -5,6 +5,7 @@ test_description='git log --graph of skewed left octopus merge.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh
t/t4215-log-skewed-merges.sh +1 -0
@@ -2,6 +2,7 @@ test_description='git log --graph of skewed merges' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh
t/t6009-rev-list-parent.sh +1 -0
@@ -5,6 +5,7 @@ test_description='ancestor culling and limiting by parent number' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_revlist () {
t/t6416-recursive-corner-cases.sh +1 -0
@@ -5,6 +5,7 @@ test_description='recursive merge corner cases involving criss-cross merges' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh
t/t6433-merge-toplevel.sh +1 -0
@@ -5,6 +5,7 @@ test_description='"git merge" top-level frontend' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh t3033_reset () {
t/t6437-submodule-merge.sh +1 -0
@@ -8,6 +8,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh
t/t7602-merge-octopus-many.sh +1 -0
@@ -4,6 +4,7 @@ test_description='git merge Testing octopus merge with more than 25 refs.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' '
t/t7603-merge-reduce-heads.sh +1 -0
@@ -4,6 +4,7 @@ test_description='git merge Testing octopus merge when reducing parents to independent branches.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # 0 - 1
t/t7607-merge-state.sh +1 -0
@@ -4,6 +4,7 @@ test_description="Test that merge state is as expected after failed merge" 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 'Ensure we restore original state if no merge strategy handles it' '
t/t7608-merge-messages.sh +1 -0
@@ -4,6 +4,7 @@ test_description='test auto-generated merge messages' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_oneline() {
Signature · 1 line
2.42.0.810.gbc538a0ee6
Re: [PATCH 03/10] merge: free result of repo_get_merge_bases()
Quoted 11 lines · Jeff King
We call
repo_get_merge_bases(), which allocates acommit_list, but never free the result, causing a leak.The obvious solution is to free it, but we need to look at the contents of the first item to decide whether to leave the loop. One option is to free it in both code paths. But since the commit that the list points to is longer-lived than the list itself, we can just dereference it immediately, free the list, and then continue with the existing logic. This is about the same amount of code, but keeps the list management all in one place.
Quoted 1 line
This lets us mark a number of merge-related test scripts as leak-free.
Wow, getting 10 newly leak-free tests for half as many lines of code is terrific. Woohoo!
Thanks,
Taylor
PATCH 4/10 commit-graph: move slab-clearing to close_commit_graph()
In reply to Jeff KingWhen closing and freeing a commit-graph, the main entry point is close_commit_graph(), which then uses close_commit_graph_one() to recurse through the base_graph links and free each one.
Commit 957ba814bf (commit-graph: when closing the graph, also release the slab, 2021-09-08) put the call to clear the slab into the recursive function, but this is pointless: there's only a single global slab variable. It works OK in practice because clearing the slab is idempotent, but it makes the code harder to reason about and refactor.
Move it into the parent function so it's only called once (and there are no other direct callers of the recursive close_commit_graph_one(), so we are not hurting them).
--- commit-graph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
commit-graph.c +1 -1
@@ -728,13 +728,13 @@ static void close_commit_graph_one(struct commit_graph *g)if (!g)return ; -clear_commit_graph_data_slab (&commit_graph_data_slab);close_commit_graph_one (g->base_graph);free_commit_graph (g); }void close_commit_graph (struct raw_object_store *o) { +clear_commit_graph_data_slab (&commit_graph_data_slab);close_commit_graph_one (o->commit_graph); o->commit_graph =NULL ; }
Signature · 1 line
2.42.0.810.gbc538a0ee6
Re: [PATCH 04/10] commit-graph: move slab-clearing to close_commit_graph()
Quoted 9 lines · Jeff King
When closing and freeing a commit-graph, the main entry point is
close_commit_graph(), which then usesclose_commit_graph_one()to recurse through thebase_graphlinks and free each one.Commit
957ba814bf(commit-graph: when closing the graph, also release the slab, 2021-09-08) put the call to clear the slab into the recursive function, but this is pointless: there's only a single global slab variable. It works OK in practice because clearing the slab is idempotent, but it makes the code harder to reason about and refactor.
Well reasoned and explained, this change makes perfect sense to me.
Thanks,
Taylor
PATCH 5/10 commit-graph: free all elements of graph chain
In reply to Jeff KingWhen running "commit-graph verify", we call free_commit_graph(). That's sufficient for the case of a single graph file, but if we loaded a chain of split graph files, they form a linked list via the base_graph pointers. We need to free all of them, or we leak all but the first struct.
We can make this work by teaching free_commit_graph() to walk the base_graph pointers and free each element. This in turn lets us simplify close_commit_graph(), which does the same thing by recursion (we cannot just use close_commit_graph() in "commit-graph verify", as the function takes a pointer to an object store, and the verify command creates a single one-off graph struct).
While indenting the code in free_commit_graph() for the loop, I noticed that setting g->data to NULL is rather pointless, as we free the struct a few lines later. So I cleaned that up while we're here.
--- commit-graph.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
commit-graph.c +11 -18
@@ -723,19 +723,10 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)return NULL ; } -static void close_commit_graph_one (struct commit_graph *g) -{ -if (!g) -return ; - -close_commit_graph_one (g->base_graph); -free_commit_graph (g); -} -void close_commit_graph (struct raw_object_store *o) {clear_commit_graph_data_slab (&commit_graph_data_slab); -close_commit_graph_one (o->commit_graph); +free_commit_graph (o->commit_graph); o->commit_graph =NULL ; }
@@ -2753,15 +2744,17 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)void free_commit_graph (struct commit_graph *g) { -if (!g) -return ; -if (g->data) { -munmap ((void *)g->data, g->data_len); - g->data =NULL ; +while (g) { +struct commit_graph *next = g->base_graph; + +if (g->data) +munmap ((void *)g->data, g->data_len); +free (g->filename); +free (g->bloom_filter_settings); +free (g); + + g = next; } -free (g->filename); -free (g->bloom_filter_settings); -free (g); }void disable_commit_graph (struct repository *r)
Signature · 1 line
2.42.0.810.gbc538a0ee6
PATCH 6/10 commit-graph: delay base_graph assignment in add_graph_to_chain()
In reply to Jeff KingWhen adding a graph to a chain, we do some consistency checks and then if everything looks good, set g->base_graph to add a link to the chain. But when we added a new consistency check in 209250ef38 (commit-graph.c:
prevent overflow in add_graph_to_chain(), 2023-07-12), it comes _after_ we've already set g->base_graph. So we might return failure, even though we actually added to the chain.
This hasn't caused a bug yet, because after failing to add to the chain, we discard the failed graph struct completely, leaking it. But in order to fix that, it's important that the struct be in a consistent and predictable state after the failure.
--- commit-graph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
commit-graph.c +2 -2
@@ -498,8 +498,6 @@ static int add_graph_to_chain(struct commit_graph *g, cur_g = cur_g->base_graph; } - g->base_graph = chain; -if (chain) {if (unsigned_add_overflows (chain->num_commits, chain->num_commits_in_base)) {
@@ -510,6 +508,8 @@ static int add_graph_to_chain(struct commit_graph *g, g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base; } + g->base_graph = chain; +return 1 ; }
Signature · 1 line
2.42.0.810.gbc538a0ee6
Re: [PATCH 06/10] commit-graph: delay base_graph assignment in add_graph_to_chain()
Quoted 31 lines · Jeff King
When adding a graph to a chain, we do some consistency checks and then if everything looks good, set
g->base_graphto add a link to the chain. But when we added a new consistency check in209250ef38(commit-graph.c:
prevent overflow inadd_graph_to_chain(), 2023-07-12), it comes _after_ we've already setg->base_graph. So we might return failure, even though we actually added to the chain.This hasn't caused a bug yet, because after failing to add to the chain, we discard the failed graph struct completely, leaking it. But in order to fix that, it's important that the struct be in a consistent and predictable state after the failure.
Signed-off-by Jeff King <[email protected]>--- commit-graph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)commit-graph.c +0
-2@@ -498,8 +498,6 @@ static int add_graph_to_chain(struct commit_graph *g, cur_g = cur_g->base_graph; } - g->base_graph = chain; -if (chain) {if (unsigned_add_overflows (chain->num_commits, chain->num_commits_in_base)) {
commit-graph.c static int add_graph_to_chain(struct commit_graph *g, · line 512
Quoted 5 lines
commit-graph.c +2
-0@@ -510,6 +508,8 @@ static int add_graph_to_chain(struct commit_graph *g, g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base; } + g->base_graph = chain; +
Oops. That looks like my fault. Thanks for catching, this switch makes sense to me.
Thanks,
Taylor
PATCH 7/10 commit-graph: free graph struct that was not added to chain
In reply to Jeff KingWhen reading the graph chain file, we open (and allocate) each individual slice it mentions and then add them to a linked-list chain. But if adding to the chain fails (e.g., because the base-graph chunk it contains didn't match what we expected), we leave the function without freeing the graph struct that caused the failure, leaking it.
We can fix it by calling free_graph_commit().
--- commit-graph.c | 2 ++ 1 file changed, 2 insertions(+)
commit-graph.c +2 -0
@@ -566,6 +566,8 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,if (add_graph_to_chain (g, graph_chain, oids, i)) { graph_chain = g; valid =1 ; + }else { +free_commit_graph (g); }break ;
Signature · 1 line
2.42.0.810.gbc538a0ee6
PATCH 8/10 commit-graph: free write-context entries before overwriting
In reply to Jeff KingWhen writing a split graph file, we replace the final element of the commit_graph_hash_after and commit_graph_filenames_after arrays. But since these are allocated strings, we need to free them before overwriting to avoid leaking the old string.
--- commit-graph.c | 2 ++ 1 file changed, 2 insertions(+)
commit-graph.c +2 -0
@@ -2065,9 +2065,11 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)free (graph_name); } +free (ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ]); ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ] =xstrdup (hash_to_hex (file_hash)); final_graph_name =get_split_graph_filename (ctx->odb, ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ]); +free (ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after -1 ]); ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after -1 ] = final_graph_name; result =rename (ctx->graph_name, final_graph_name);
Signature · 1 line
2.42.0.810.gbc538a0ee6
Re: [PATCH 08/10] commit-graph: free write-context entries before overwriting
Quoted 6 lines · Jeff King
commit-graph.c +0
-0@@ -2065,9 +2065,11 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)free (graph_name);
commit-graph.c static int write_commit_graph_file(struct write_commit_graph_context *ctx) · line 2075
Quoted 10 lines
commit-graph.c +2
-0} +free (ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ]); ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ] =xstrdup (hash_to_hex (file_hash)); final_graph_name =get_split_graph_filename (ctx->odb, ctx->commit_graph_hash_after[ctx->num_commit_graphs_after -1 ]); +free (ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after -1 ]); ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after -1 ] = final_graph_name; result =rename (ctx->graph_name, final_graph_name);
This hunk makes sense. It might be nice in the future to do something like:
--- 8< ---
commit-graph.c +6 -7
@@ -59,7 +59,7 @@ void git_test_write_commit_graph_or_die(void)#define GRAPH_EXTRA_EDGES_NEEDED 0x80000000#define GRAPH_EDGE_LAST_MASK 0x7fffffff -#define GRAPH_PARENT_NONE 0x70000000 +tdefine GRAPH_PARENT_NONE 0x70000000#define GRAPH_LAST_EDGE 0x80000000
@@ -1033,11 +1033,11 @@ struct write_commit_graph_context {uint64_t progress_cnt;char *base_graph_name; -int num_commit_graphs_before; -int num_commit_graphs_after; -char **commit_graph_filenames_before; -char **commit_graph_filenames_after; -char **commit_graph_hash_after; +struct { +size_t nr; +char **fname; +char **hash; + } graphs_before, graphs_after;uint32_t new_num_commits_in_base;struct commit_graph *new_base_graph; --- >8 ---
...making the corresponding changes throughout the rest of the file. But that is definitely out of scope here, and could easily be left for another day.
#leftoverbits
Thanks,
Taylor
Re: [PATCH 08/10] commit-graph: free write-context entries before overwriting
Quoted 18 lines · Taylor Blau
commit-graph.c +5
-6@@ -1033,11 +1033,11 @@ struct write_commit_graph_context {uint64_t progress_cnt;char *base_graph_name; -int num_commit_graphs_before; -int num_commit_graphs_after; -char **commit_graph_filenames_before; -char **commit_graph_filenames_after; -char **commit_graph_hash_after; +struct { +size_t nr; +char **fname; +char **hash; + } graphs_before, graphs_after;uint32_t new_num_commits_in_base;struct commit_graph *new_base_graph; --- >8 ---
Quoted 3 lines
...making the corresponding changes throughout the rest of the file. But that is definitely out of scope here, and could easily be left for another day.
I agree that it would make things a bit more readable, but there currently is no "hash_before". So they're not quite symmetric.
-Peff
PATCH 9/10 commit-graph: free write-context base_graph_name during cleanup
In reply to Jeff KingCommit 6c622f9f0b (commit-graph: write commit-graph chains, 2019-06-18) added a base_graph_name string to the write_commit_graph_context struct. But the end-of-function cleanup forgot to free it, causing a leak.
This (presumably in combination with the preceding leak-fixes) lets us mark t5328 as leak-free.
--- commit-graph.c | 1 + t/t5328-commit-graph-64bit-time.sh | 2 ++ 2 files changed, 3 insertions(+)
commit-graph.c +1 -0
@@ -2518,6 +2518,7 @@ int write_commit_graph(struct object_directory *odb, cleanup:free (ctx->graph_name); +free (ctx->base_graph_name);free (ctx->commits.list);oid_array_clear (&ctx->oids);clear_topo_level_slab (&topo_levels);
t/t5328-commit-graph-64bit-time.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='commit graph with 64-bit timestamps' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh if ! test_have_prereq TIME_IS_64BIT || ! test_have_prereq TIME_T_IS_64BIT
Signature · 1 line
2.42.0.810.gbc538a0ee6
PATCH 10/10 commit-graph: clear oidset after finishing write
In reply to Jeff KingIn graph_write() we store commits in an oidset, but never clean it up, leaking the contents. We should clear it in the cleanup section.
The oidset comes from 6830c36077 (commit-graph.h: replace 'commit_hex' with 'commits', 2020-04-13), but it was just replacing a string_list that was also leaked. Curiously, we fixed the leak of some adjacent variables in commit fa8953cb40 (builtin/commit-graph.c: extract 'read_one_commit()', 2020-05-18), but the oidset wasn't included for some reason.
In combination with the preceding commits, this lets us mark t5324 as leak-free.
--- builtin/commit-graph.c | 1 + t/t5324-split-commit-graph.sh | 2 ++ 2 files changed, 3 insertions(+)
builtin/commit-graph.c +1 -0
@@ -311,6 +311,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)FREE_AND_NULL (options);string_list_clear (&pack_indexes,0 );strbuf_release (&buf); +oidset_clear (&commits);return result; }
t/t5324-split-commit-graph.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='split commit graph' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_TEST_COMMIT_GRAPH=0
Signature · 1 line
2.42.0.810.gbc538a0ee6
Is SANITIZE=leak make test unreliable for anyone else?
In reply to Jeff KingJeff,
Please accept my apologies for slightly hijacking your posting, but I see you have been fixing some leaks, and so presumably you are familiar with building git with "SANITIZE=leak".
I have fixed some leaks in my SHA1+SHA256 patchset recently and while tracking them down I found that simply enabling SANITIZE=leak caused "make test" on git v2.42 without patches to give different failures from test run to test run.
Well actually I wound up with the following command line:
GIT_TEST_PASSING_SANITIZE_LEAK=true GIT_TEST_SANITIZE_LEAK_LOG=true SANITIZE=leak DEVELOPER=1 make test
I had removed "-j32" to make things more reproducible.
I observed this unreliability with SANITIZE=leak when building git on an fully updated version of debian 12.
My big question is:
Do other people see random test failures when SANITIZE=leak is enabled?
Is it just me?
Thanks,
Eric
Re: Is SANITIZE=leak make test unreliable for anyone else?
Quoted 5 lines · Eric W. Biederman
My big question is:
Do other people see random test failures when SANITIZE=leak is enabled?
Is it just me?
Yes, I've seen this. You mentioned that you were testing with v2.42, which lacks 370ef7e40d (test-lib: ignore uninteresting LSan output, 2023-08-28). Try using the current version of 'master', or just cherry-picking that commit onto v2.42.
A few other tips to avoid confusing results (though they at least do not vary from run to run):
- use the LEAK_LOG option, since you otherwise miss some cases (it looks like you already are from what you posted above)
- gcc and clang sometimes produce different results. Right now I get no leak from gcc on t9004, but clang reports one (I think clang is right here)
- turn off compiler optimizations; we've had cases where code reordering/removal creates false positives. Oh, hmm, I forgot we do this by default since d3775de074 (Makefile: force -O0 when compiling with SANITIZE=leak, 2022-10-18), so your v2.42 should be covered.
-Peff
Re: Is SANITIZE=leak make test unreliable for anyone else?
Quoted 19 lines · Jeff King
Quoted 5 lines · Eric W. Biederman
My big question is:
Do other people see random test failures when SANITIZE=leak is enabled?
Is it just me?
Yes, I've seen this. You mentioned that you were testing with v2.42, which lacks
370ef7e40d(test-lib: ignore uninteresting LSan output, 2023-08-28). Try using the current version of 'master', or just cherry-picking that commit onto v2.42.A few other tips to avoid confusing results (though they at least do not vary from run to run):
- use the
LEAK_LOGoption, since you otherwise miss some cases (it looks like you already are from what you posted above)
Quoted 8 lines
- gcc and clang sometimes produce different results. Right now I get no leak from gcc on t9004, but clang reports one (I think clang is right here)
- turn off compiler optimizations; we've had cases where code reordering/removal creates false positives. Oh, hmm, I forgot we do this by default since
d3775de074(Makefile: force -O0 when compiling with SANITIZE=leak, 2022-10-18), so your v2.42 should be covered.
I just tried master, aka commit d0e8084c65cb ("The fourteenth batch").
What I see on a random failure looks like:
Quoted 8 lines
make -C t/ all
make[1]: Entering directory '/home/user/projects/git/git/t'
rm -f -r 'test-results'
GIT_TEST_EXT_CHAIN_LINT=0 && exportGIT_TEST_EXT_CHAIN_LINT&& make aggregate-results-and-cleanup make[2]: Entering directory '/home/user/projects/git/git/t'
***t0000-basic.sh***
Segmentation fault
error:test_bool_envrequires bool values both for $GIT_TEST_PASSING_SANITIZE_LEAK and for the default fallback
Which doesn't sound like anything you have described so I am guessing it is something with my environment I need to track down.
Eric
Re: Is SANITIZE=leak make test unreliable for anyone else?
Quoted 11 lines · Eric W. Biederman
What I see on a random failure looks like:
Quoted 8 lines
make -C t/ all
make[1]: Entering directory '/home/user/projects/git/git/t'
rm -f -r 'test-results'
GIT_TEST_EXT_CHAIN_LINT=0 && exportGIT_TEST_EXT_CHAIN_LINT&& make aggregate-results-and-cleanup make[2]: Entering directory '/home/user/projects/git/git/t'
***t0000-basic.sh***
Segmentation fault
error:test_bool_envrequires bool values both for $GIT_TEST_PASSING_SANITIZE_LEAK and for the default fallback
Quoted 2 lines
Which doesn't sound like anything you have described so I am guessing it is something with my environment I need to track down.
No, that seems different entirely. You'll have to figure out which program is segfaulting and why (if you can see it in a script besides t0000 you're probably better off, as that one is a maze of tests-within-tests, since it is testing the test-harness itself).
Although the "error" you see maybe implies that it is failing early on in test-lib.sh, when we are calling "test-tool env-helper". If that is segfaulting there is probably something very wrong with your build.
-Peff
Re: Is SANITIZE=leak make test unreliable for anyone else?
Quoted 16 lines · Jeff King
Quoted 11 lines · Eric W. Biederman
What I see on a random failure looks like:
Quoted 8 lines
make -C t/ all
make[1]: Entering directory '/home/user/projects/git/git/t'
rm -f -r 'test-results'
GIT_TEST_EXT_CHAIN_LINT=0 && exportGIT_TEST_EXT_CHAIN_LINT&& make aggregate-results-and-cleanup make[2]: Entering directory '/home/user/projects/git/git/t'
***t0000-basic.sh***
Segmentation fault
error:test_bool_envrequires bool values both for $GIT_TEST_PASSING_SANITIZE_LEAK and for the default fallbackQuoted 2 lines
Which doesn't sound like anything you have described so I am guessing it is something with my environment I need to track down.
Quoted 8 lines
No, that seems different entirely. You'll have to figure out which program is segfaulting and why (if you can see it in a script besides t0000 you're probably better off, as that one is a maze of tests-within-tests, since it is testing the test-harness itself).
Although the "error" you see maybe implies that it is failing early on in
test-lib.sh, when we are calling "test-tool env-helper". If that is segfaulting there is probably something very wrong with your build.
Just to document what I am seeing it appears to be some odd interaction with address space randomization.
If I run my make as: "setarch --addr-no-randomize make test"
I don't see coredumps any more.
Now to dig a deeper and see if I can figure out what about address space randomization is making things break.
Eric
Quoted 10 lines · Jeff King
I noticed while working on the jk/commit-graph-verify-fix topic that
free_commit_graph()leaks any slices of a commit-graph-chain except for the first. I naively hoped that fixing that would make t5324 leak-free, but it turns out there were a number of other leaks, so I fixed those, too. A couple of them were in the merge code, which in turn means a bunch of new test scripts are now leak-free.Even though I saw the problem on that other topic, there's no dependency here; this series can be applied directly to master (or possibly even maint, though I didn't try).
Thanks for carefully finding and explaining these various leaks. The series is a definite improvement, and after reviewing closely I couldn't find anything worth changing. LGTM!
Thanks,
Taylor
Quoted 8 lines · Taylor Blau
Quoted 7 lines · Jeff King
I noticed while working on the jk/commit-graph-verify-fix topic that
free_commit_graph()leaks any slices of a commit-graph-chain except for the first. I naively hoped that fixing that would make t5324 leak-free, but it turns out there were a number of other leaks, so I fixed those, too. A couple of them were in the merge code, which in turn means a bunch of new test scripts are now leak-free.
Quoted 7 lines
Quoted 3 lines
Even though I saw the problem on that other topic, there's no dependency here; this series can be applied directly to master (or possibly even maint, though I didn't try).
Thanks for carefully finding and explaining these various leaks. The series is a definite improvement, and after reviewing closely I couldn't find anything worth changing. LGTM!
Thanks, both. Let's merge it down to 'next'.