[PATCH 09/11] commit-graph: avoid using stale stack addresses
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 15, 2025, 13:11 UTC
- Message-ID
- <077bcab206f5bfc9fc10a28ad7b726a6ec16c2bb.1747314709.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1891.git.1747314709.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
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> --- commit-graph.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/commit-graph.c b/commit-graph.c index 9f0115dac9b5..d052c1bf15c5 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -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);
-- gitgitgadget