]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: fix memory leak in fetch_and_setup_pack_index()
authorLorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Mon, 1 Jun 2026 13:52:12 +0000 (15:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Jun 2026 22:57:52 +0000 (07:57 +0900)
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>
http.c

diff --git a/http.c b/http.c
index 55dd856a279a23e191c72598abc7e8b4cc426080..d50a34e4460a9077a4b715d0a1b5f4125f13159e 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2614,11 +2614,13 @@ static int fetch_and_setup_pack_index(struct packfile_list *packs,
        }
 
        ret = verify_pack_index(new_pack);
-       if (!ret)
-               close_pack_index(new_pack);
+
+       close_pack_index(new_pack);
        free(tmp_idx);
-       if (ret)
+       if (ret) {
+               free(new_pack);
                return -1;
+       }
 
        packfile_list_prepend(packs, new_pack);
        return 0;