[PATCH v3 2/2] http: fix memory leak in fetch_and_setup_pack_index()
- From
LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
- Date
- Jun 1, 2026, 13:52 UTC
- Message-ID
- <e5b2347a4d48841e5dac33b6f36b6200d50a84c0.1780321770.git.lorenzo.pegorari2002@gmail.com>
- In-Reply-To
- <cover.1780321770.git.lorenzo.pegorari2002@gmail.com>
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> --- http.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/http.c b/http.c index b8443b1ef4..99da4d7529 100644 --- a/http.c +++ b/http.c @@ -2543,11 +2543,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;
-- 2.54.0.129.g2dffd77b94.dirty