In pack-bitmap.c:load_bitmap_entries_v1, the function read_bitmap_1 allocates a bitmap and reads index data into it. However, if any of the validation checks following the allocation fail, the allocated bitmap is not freed, resulting in a memory leak. To avoid this, the validation checks should be performed before the bitmap is allocated. Lidong Yan (2): pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed pack-bitmap: add loading corrupt bitmap_index test Taylor Blau (1): pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed pack-bitmap.c | 29 +++++++----------------- t/t5310-pack-bitmaps.sh | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 21 deletions(-) base-commit: cb96e1697ad6e54d11fc920c95f82977f8e438f8 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1962%2Fbrandb97%2Ffix-pack-bitmap-leak-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1962/brandb97/fix-pack-bitmap-leak-v2 Pull-Request: https://github.com/git/git/pull/1962 Range-diff vs v1: 1: 00168766edf = 1: 130c3dc5dcd pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed -: ----------- > 2: b515c278a8f pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed -: ----------- > 3: 5be22d563af pack-bitmap: add loading corrupt bitmap_index test -- gitgitgadget