http: fix memory leak in fetch_and_setup_pack_index()

Inside the function `fetch_and_setup_pack_index()`, when the pack obtained using `parse_pack_index()` fails to be verified by `verify_pack_index()`, the function returns without closing and freeing said pack. Fix this by calling `close_pack_index()` to munmap the index file for the leaking pack (which might have been mmapped by `fetch_pack_index()` or `verify_pack_index()`), and then free it, when the verification fails. Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

LorenzoPegorari committed Jun 1, 2026 at 15:52 UTC 18decad922884a69ea39c0332f7a94ce82cf99cc
1 file changed +5 -3
http.c
+5 -3
@@ -2614,11 +2614,13 @@ static int fetch_and_setup_pack_index(struct packfile_list *packs,
2614 }
2615
2616 ret = verify_pack_index(new_pack);
2617 - if (!ret)
2618 - close_pack_index(new_pack);
2617 +
2618 + close_pack_index(new_pack);
2619 free(tmp_idx);
2620 - if (ret)
2620 + if (ret) {
2621 + free(new_pack);
2622 return -1;
2623 + }
2624
2625 packfile_list_prepend(packs, new_pack);
2626 return 0;