aboutsummaryrefslogtreecommitdiff
path: root/pack-bitmap.c
diff options
context:
space:
mode:
authorLidong Yan <502024330056@smail.nju.edu.cn>2025-05-12 12:22:10 +0000
committerJunio C Hamano <gitster@pobox.com>2025-05-12 10:58:35 -0700
commit7291c2be6a276f8b3693fb7d8dd763cee14c2485 (patch)
treef9b3168c3a655a8b1d30b46e5185c36ed3ea3998 /pack-bitmap.c
parent7a1d2bd0a596f42a8a7a68d55577967bb454fec0 (diff)
downloadgit-7291c2be6a276f8b3693fb7d8dd763cee14c2485.tar.xz
pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed
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. Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-bitmap.c')
-rw-r--r--pack-bitmap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b9f1d86604..ac6d62b980 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -388,10 +388,6 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
return error(_("corrupt ewah bitmap: commit index %u out of range"),
(unsigned)commit_idx_pos);
- bitmap = read_bitmap_1(index);
- if (!bitmap)
- return -1;
-
if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
return error(_("corrupted bitmap pack index"));
@@ -402,6 +398,10 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
return error(_("invalid XOR offset in bitmap pack index"));
}
+ bitmap = read_bitmap_1(index);
+ if (!bitmap)
+ return -1;
+
recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
index, bitmap, &oid, xor_bitmap, flags);
}