Skip to content

Commit 51a94d8

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a04790 commit 51a94d8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

commit-graph.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
16851685
struct strbuf progress_title = STRBUF_INIT;
16861686
struct strbuf packname = STRBUF_INIT;
16871687
int dirlen;
1688+
int ret = 0;
16881689

16891690
strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
16901691
dirlen = packname.len;
@@ -1703,24 +1704,25 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
17031704
strbuf_addstr(&packname, pack_indexes->items[i].string);
17041705
p = add_packed_git(packname.buf, packname.len, 1);
17051706
if (!p) {
1706-
error(_("error adding pack %s"), packname.buf);
1707-
return -1;
1707+
ret = error(_("error adding pack %s"), packname.buf);
1708+
goto cleanup;
17081709
}
17091710
if (open_pack_index(p)) {
1710-
error(_("error opening index for %s"), packname.buf);
1711-
return -1;
1711+
ret = error(_("error opening index for %s"), packname.buf);
1712+
goto cleanup;
17121713
}
17131714
for_each_object_in_pack(p, add_packed_commits, ctx,
17141715
FOR_EACH_OBJECT_PACK_ORDER);
17151716
close_pack(p);
17161717
free(p);
17171718
}
17181719

1720+
cleanup:
17191721
stop_progress(&ctx->progress);
17201722
strbuf_release(&progress_title);
17211723
strbuf_release(&packname);
17221724

1723-
return 0;
1725+
return ret;
17241726
}
17251727

17261728
static int fill_oids_from_commits(struct write_commit_graph_context *ctx,

0 commit comments

Comments
 (0)