commit-graph: avoid using stale stack addresses
The code is a bit too hard to reason about to fully assess whether the `fill_commit_graph_info()` function is called at all after `write_commit_graph()` returns (and hence the stack variable `topo_levels` goes out of context). Let's simply make sure that the stack address is no longer used at that stage, thereby making the code quite a bit easier to reason about. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
May 15, 2025 at 13:11 UTC
ee63d026b407118221aca455a9c4f03a08ecf648
1 file changed
+9
commit-graph.c
+9
@@ -2683,6 +2683,15 @@ cleanup:
2683
oid_array_clear(&ctx.oids);
2684
clear_topo_level_slab(&topo_levels);
2685
2686
+ if (ctx.r->objects->commit_graph) {
2687
+ struct commit_graph *g = ctx.r->objects->commit_graph;
2688
+
2689
+ while (g) {
2690
+ g->topo_levels = NULL;
2691
+ g = g->base_graph;
2692
+ }
2693
+ }
2694
+
2695
for (i = 0; i < ctx.num_commit_graphs_before; i++)
2696
free(ctx.commit_graph_filenames_before[i]);
2697
free(ctx.commit_graph_filenames_before);