Skip to content

Commit a45edde

Browse files
committed
Merge branch 'jk/commit-graph-leak-fixes'
Leakfix. * jk/commit-graph-leak-fixes: commit-graph: clear oidset after finishing write commit-graph: free write-context base_graph_name during cleanup commit-graph: free write-context entries before overwriting commit-graph: free graph struct that was not added to chain commit-graph: delay base_graph assignment in add_graph_to_chain() commit-graph: free all elements of graph chain commit-graph: move slab-clearing to close_commit_graph() merge: free result of repo_get_merge_bases() commit-reach: free temporary list in get_octopus_merge_bases() t6700: mark test as leak-free
2 parents c75e914 + da09e7a commit a45edde

18 files changed

+42
-22
lines changed

builtin/commit-graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)
328328
FREE_AND_NULL(options);
329329
string_list_clear(&pack_indexes, 0);
330330
strbuf_release(&buf);
331+
oidset_clear(&commits);
331332
return result;
332333
}
333334

builtin/merge.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16321632

16331633
for (j = remoteheads; j; j = j->next) {
16341634
struct commit_list *common_one;
1635+
struct commit *common_item;
16351636

16361637
/*
16371638
* Here we *have* to calculate the individual
@@ -1641,7 +1642,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16411642
common_one = repo_get_merge_bases(the_repository,
16421643
head_commit,
16431644
j->item);
1644-
if (!oideq(&common_one->item->object.oid, &j->item->object.oid)) {
1645+
common_item = common_one->item;
1646+
free_commit_list(common_one);
1647+
if (!oideq(&common_item->object.oid, &j->item->object.oid)) {
16451648
up_to_date = 0;
16461649
break;
16471650
}

commit-graph.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,6 @@ static int add_graph_to_chain(struct commit_graph *g,
523523
cur_g = cur_g->base_graph;
524524
}
525525

526-
g->base_graph = chain;
527-
528526
if (chain) {
529527
if (unsigned_add_overflows(chain->num_commits,
530528
chain->num_commits_in_base)) {
@@ -535,6 +533,8 @@ static int add_graph_to_chain(struct commit_graph *g,
535533
g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base;
536534
}
537535

536+
g->base_graph = chain;
537+
538538
return 1;
539539
}
540540

@@ -601,6 +601,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
601601
if (add_graph_to_chain(g, graph_chain, oids, i)) {
602602
graph_chain = g;
603603
valid = 1;
604+
} else {
605+
free_commit_graph(g);
604606
}
605607

606608
break;
@@ -752,19 +754,10 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
752754
return NULL;
753755
}
754756

755-
static void close_commit_graph_one(struct commit_graph *g)
756-
{
757-
if (!g)
758-
return;
759-
760-
clear_commit_graph_data_slab(&commit_graph_data_slab);
761-
close_commit_graph_one(g->base_graph);
762-
free_commit_graph(g);
763-
}
764-
765757
void close_commit_graph(struct raw_object_store *o)
766758
{
767-
close_commit_graph_one(o->commit_graph);
759+
clear_commit_graph_data_slab(&commit_graph_data_slab);
760+
free_commit_graph(o->commit_graph);
768761
o->commit_graph = NULL;
769762
}
770763

@@ -2101,9 +2094,11 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
21012094
free(graph_name);
21022095
}
21032096

2097+
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
21042098
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
21052099
final_graph_name = get_split_graph_filename(ctx->odb,
21062100
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
2101+
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
21072102
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
21082103

21092104
result = rename(ctx->graph_name, final_graph_name);
@@ -2552,6 +2547,7 @@ int write_commit_graph(struct object_directory *odb,
25522547

25532548
cleanup:
25542549
free(ctx->graph_name);
2550+
free(ctx->base_graph_name);
25552551
free(ctx->commits.list);
25562552
oid_array_clear(&ctx->oids);
25572553
clear_topo_level_slab(&topo_levels);
@@ -2782,15 +2778,17 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
27822778

27832779
void free_commit_graph(struct commit_graph *g)
27842780
{
2785-
if (!g)
2786-
return;
2787-
if (g->data) {
2788-
munmap((void *)g->data, g->data_len);
2789-
g->data = NULL;
2781+
while (g) {
2782+
struct commit_graph *next = g->base_graph;
2783+
2784+
if (g->data)
2785+
munmap((void *)g->data, g->data_len);
2786+
free(g->filename);
2787+
free(g->bloom_filter_settings);
2788+
free(g);
2789+
2790+
g = next;
27902791
}
2791-
free(g->filename);
2792-
free(g->bloom_filter_settings);
2793-
free(g);
27942792
}
27952793

27962794
void disable_commit_graph(struct repository *r)

commit-reach.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
173173
for (k = bases; k; k = k->next)
174174
end = k;
175175
}
176+
free_commit_list(ret);
176177
ret = new_commits;
177178
}
178179
return ret;

t/t4214-log-graph-octopus.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='git log --graph of skewed left octopus merge.'
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
. "$TEST_DIRECTORY"/lib-log-graph.sh
1011

t/t4215-log-skewed-merges.sh

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

33
test_description='git log --graph of skewed merges'
44

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

t/t5324-split-commit-graph.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='split commit graph'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
GIT_TEST_COMMIT_GRAPH=0

t/t5328-commit-graph-64bit-time.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='commit graph with 64-bit timestamps'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
if ! test_have_prereq TIME_IS_64BIT || ! test_have_prereq TIME_T_IS_64BIT

t/t5521-pull-options.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='pull options'
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/t6009-rev-list-parent.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='ancestor culling and limiting by parent number'
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
check_revlist () {

0 commit comments

Comments
 (0)