summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorLibravatar Ævar Arnfjörð Bjarmason <avarab@gmail.com>2022-03-04 19:32:13 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-03-04 13:24:19 -0800
commit51a94d8ffe57ff40e1db1d5e46a1864a5ded7f49 (patch)
tree3d8cb22238e053b92a88f622430efa03b430d324 /commit-graph.c
parentcommit-graph: fix memory leak in misused string_list API (diff)
downloadtgif-51a94d8ffe57ff40e1db1d5e46a1864a5ded7f49.tar.xz
commit-graph: stop fill_oids_from_packs() progress on error and free()
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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c12
1 files 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,