Skip to content

Commit 4efa930

Browse files
pks-tgitster
authored andcommitted
commit-graph: fix memory leak when not writing graph
When `write_commit_graph()` bails out writing a split commit-graph early then it may happen that we have already gathered the set of existing commit-graph file names without yet determining the new merged set of files. This can result in a memory leak though because we only clear the preimage of files when we have collected the postimage. Fix this issue by dropping the condition altogether so that we always try to free both preimage and postimage filenames. As the context structure is zero-initialized this simplification is safe to do. Signed-off-by: Patrick Steinhardt <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4dbce1 commit 4efa930

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

commit-graph.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,19 +2616,16 @@ int write_commit_graph(struct object_directory *odb,
26162616
oid_array_clear(&ctx->oids);
26172617
clear_topo_level_slab(&topo_levels);
26182618

2619-
if (ctx->commit_graph_filenames_after) {
2620-
for (i = 0; i < ctx->num_commit_graphs_after; i++) {
2621-
free(ctx->commit_graph_filenames_after[i]);
2622-
free(ctx->commit_graph_hash_after[i]);
2623-
}
2624-
2625-
for (i = 0; i < ctx->num_commit_graphs_before; i++)
2626-
free(ctx->commit_graph_filenames_before[i]);
2619+
for (i = 0; i < ctx->num_commit_graphs_before; i++)
2620+
free(ctx->commit_graph_filenames_before[i]);
2621+
free(ctx->commit_graph_filenames_before);
26272622

2628-
free(ctx->commit_graph_filenames_after);
2629-
free(ctx->commit_graph_filenames_before);
2630-
free(ctx->commit_graph_hash_after);
2623+
for (i = 0; i < ctx->num_commit_graphs_after; i++) {
2624+
free(ctx->commit_graph_filenames_after[i]);
2625+
free(ctx->commit_graph_hash_after[i]);
26312626
}
2627+
free(ctx->commit_graph_filenames_after);
2628+
free(ctx->commit_graph_hash_after);
26322629

26332630
free(ctx);
26342631

0 commit comments

Comments
 (0)