From bdf58f9cf8d2669480d28dd07a884ac52f8846ac Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 8 Aug 2023 15:22:40 -0400 Subject: [PATCH] commit-graph: fix small leak with invalid changedPathsVersion When writing a commit graph, we sanity-check the value of commitgraph.changedPathsVersion and return early if it's invalid. But we only do so after allocating the write_commit_graph_context, meaing we leak it. We could "goto cleanup" to fix this, but instead let's push this check to the top of the function with the other early checks which return before doing any work. Signed-off-by: Jeff King Acked-by: Taylor Blau Signed-off-by: Junio C Hamano --- commit-graph.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 38edb12669..ccc21c6708 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2372,6 +2372,12 @@ int write_commit_graph(struct object_directory *odb, } if (!commit_graph_compatible(r)) return 0; + if (r->settings.commit_graph_changed_paths_version < -1 + || r->settings.commit_graph_changed_paths_version > 2) { + warning(_("attempting to write a commit-graph, but 'commitgraph.changedPathsVersion' (%d) is not supported"), + r->settings.commit_graph_changed_paths_version); + return 0; + } CALLOC_ARRAY(ctx, 1); ctx->r = r; @@ -2384,12 +2390,6 @@ int write_commit_graph(struct object_directory *odb, ctx->write_generation_data = (get_configured_generation_version(r) == 2); ctx->num_generation_data_overflows = 0; - if (r->settings.commit_graph_changed_paths_version < -1 - || r->settings.commit_graph_changed_paths_version > 2) { - warning(_("attempting to write a commit-graph, but 'commitgraph.changedPathsVersion' (%d) is not supported"), - r->settings.commit_graph_changed_paths_version); - return 0; - } bloom_settings.hash_version = r->settings.commit_graph_changed_paths_version == 2 ? 2 : 1; bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",