From 51a94d8ffe57ff40e1db1d5e46a1864a5ded7f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 4 Mar 2022 19:32:13 +0100 Subject: [PATCH] commit-graph: stop fill_oids_from_packs() progress on error and free() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a bug in fill_oids_from_packs(), we should always stop_progress(), but did not do so if we returned an error here. This also plugs a memory leak in those cases by releasing the two "struct strbuf" variables the function uses. While I'm at it stop hardcoding "-1" here and just use the return value of error() instead, which happens to be "-1". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- commit-graph.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index d0c94600ba..aab0b29277 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1685,6 +1685,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, struct strbuf progress_title = STRBUF_INIT; struct strbuf packname = STRBUF_INIT; int dirlen; + int ret = 0; strbuf_addf(&packname, "%s/pack/", ctx->odb->path); dirlen = packname.len; @@ -1703,12 +1704,12 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, strbuf_addstr(&packname, pack_indexes->items[i].string); p = add_packed_git(packname.buf, packname.len, 1); if (!p) { - error(_("error adding pack %s"), packname.buf); - return -1; + ret = error(_("error adding pack %s"), packname.buf); + goto cleanup; } if (open_pack_index(p)) { - error(_("error opening index for %s"), packname.buf); - return -1; + ret = error(_("error opening index for %s"), packname.buf); + goto cleanup; } for_each_object_in_pack(p, add_packed_commits, ctx, FOR_EACH_OBJECT_PACK_ORDER); @@ -1716,11 +1717,12 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, free(p); } +cleanup: stop_progress(&ctx->progress); strbuf_release(&progress_title); strbuf_release(&packname); - return 0; + return ret; } static int fill_oids_from_commits(struct write_commit_graph_context *ctx,