commit-graph: fix memory leak when fill_oids_from_packs() fails

In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,
memory allocated and returned by add_packed_git will leak. Simply
add close_pack and free(p) will solve this problem.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Lidong Yan
2025-05-09 08:30:35 +00:00
committed by Junio C Hamano
parent 1a8a4971cc
commit beccbddb68

View File

@@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
} }
if (open_pack_index(p)) { if (open_pack_index(p)) {
ret = error(_("error opening index for %s"), packname.buf); ret = error(_("error opening index for %s"), packname.buf);
close_pack(p);
free(p);
goto cleanup; goto cleanup;
} }
for_each_object_in_pack(p, add_packed_commits, ctx, for_each_object_in_pack(p, add_packed_commits, ctx,