]> git.ipfire.org Git - thirdparty/git.git/commit
commit-graph: delay base_graph assignment in add_graph_to_chain()
authorJeff King <peff@peff.net>
Tue, 3 Oct 2023 20:30:04 +0000 (16:30 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Oct 2023 21:28:24 +0000 (14:28 -0700)
commit991d549f74862d07a38a077f34c0deaf65607c74
tree60aaef8fddfa63ee05da3adb929d66d7af6b7ebc
parent09a75abba4eabab3f2cc4474e5d2db3a33a3a682
commit-graph: delay base_graph assignment in add_graph_to_chain()

When adding a graph to a chain, we do some consistency checks and then
if everything looks good, set g->base_graph to add a link to the chain.
But when we added a new consistency check in 209250ef38 (commit-graph.c:
prevent overflow in add_graph_to_chain(), 2023-07-12), it comes _after_
we've already set g->base_graph. So we might return failure, even though
we actually added to the chain.

This hasn't caused a bug yet, because after failing to add to the chain,
we discard the failed graph struct completely, leaking it. But in order
to fix that, it's important that the struct be in a consistent and
predictable state after the failure.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c