Skip to content

Commit 7291c2b

Browse files
brandb97gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a1d2bd commit 7291c2b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pack-bitmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
388388
return error(_("corrupt ewah bitmap: commit index %u out of range"),
389389
(unsigned)commit_idx_pos);
390390

391-
bitmap = read_bitmap_1(index);
392-
if (!bitmap)
393-
return -1;
394-
395391
if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
396392
return error(_("corrupted bitmap pack index"));
397393

@@ -402,6 +398,10 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
402398
return error(_("invalid XOR offset in bitmap pack index"));
403399
}
404400

401+
bitmap = read_bitmap_1(index);
402+
if (!bitmap)
403+
return -1;
404+
405405
recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
406406
index, bitmap, &oid, xor_bitmap, flags);
407407
}

0 commit comments

Comments
 (0)