]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: avoid using stale stack addresses
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 15 May 2025 13:11:47 +0000 (13:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 May 2025 20:46:48 +0000 (13:46 -0700)
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>
commit-graph.c

index 9f0115dac9b528405ddd35fe5f1664f247e8b832..d052c1bf15c5134628a892fbe9a03c9414654f73 100644 (file)
@@ -2683,6 +2683,15 @@ cleanup:
        oid_array_clear(&ctx.oids);
        clear_topo_level_slab(&topo_levels);
 
+       if (ctx.r->objects->commit_graph) {
+               struct commit_graph *g = ctx.r->objects->commit_graph;
+
+               while (g) {
+                       g->topo_levels = NULL;
+                       g = g->base_graph;
+               }
+       }
+
        for (i = 0; i < ctx.num_commit_graphs_before; i++)
                free(ctx.commit_graph_filenames_before[i]);
        free(ctx.commit_graph_filenames_before);