Skip to content

Commit

Permalink
block: fix memory leak of bvec
Browse files Browse the repository at this point in the history
bio_init() clears bio instance, so the bvec index has to be set after
bio_init(), otherwise bio->bi_io_vec may be leaked.

Fixes: 3175199 ("block: split bio_kmalloc from bio_alloc_bioset")
Cc: Johannes Thumshirn <[email protected]>
Cc: Chaitanya Kulkarni <[email protected]>
Cc: Damien Le Moal <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Ming Lei authored and axboe committed Feb 2, 2021
1 parent a42e0d7 commit 8358c28
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
if (unlikely(!bvl))
goto err_free;

bio->bi_flags |= idx << BVEC_POOL_OFFSET;
bio_init(bio, bvl, bvec_nr_vecs(idx));
bio->bi_flags |= idx << BVEC_POOL_OFFSET;
} else if (nr_iovecs) {
bio_init(bio, bio->bi_inline_vecs, BIO_INLINE_VECS);
} else {
Expand Down

0 comments on commit 8358c28

Please sign in to comment.