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>

Lidong Yan committed May 9, 2025 at 08:30 UTC beccbddb6802c0b56e34bb1d55cecceb093940f4
1 file changed +2
commit-graph.c
+2
@@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
1929 }
1930 if (open_pack_index(p)) {
1931 ret = error(_("error opening index for %s"), packname.buf);
1932 + close_pack(p);
1933 + free(p);
1934 goto cleanup;
1935 }
1936 for_each_object_in_pack(p, add_packed_commits, ctx,