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 <ps@pks.im> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 18, 2023 at 11:02 UTC
4efa9308eabba5b474f7ff5b43a8a7b767b6de79
1 file changed
+8
-11
commit-graph.c
+8
-11
@@ -2616,19 +2616,16 @@ cleanup:
2616
oid_array_clear(&ctx->oids);
2617
clear_topo_level_slab(&topo_levels);
2618
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);
2622
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]);
2626
}
2627
+ free(ctx->commit_graph_filenames_after);
2628
+ free(ctx->commit_graph_hash_after);
2629
2630
free(ctx);
2631