block: fix memory leak of bvec
PATCH 1/1 block: fix memory leak of bvec
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 3175199ab0ac ("block: split bio_kmalloc from bio_alloc_bioset")
Cc Christoph Hellwig <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Chaitanya Kulkarni <[email protected]>
Cc Damien Le Moal <[email protected]>
Signed-off-by Ming Lei <[email protected]>
--- block/bio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/bio.c +1 -1
@@ -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 {
Signature · 1 line
2.29.2
Quoted 2 lines · Ming Lei
bio_init()clears bio instance, so the bvec index has to be set afterbio_init(), otherwisebio->bi_io_vecmay be leaked.
Yeah, I've got exactly the same test sitting here as part of a larger series:
Reviewed-by Christoph Hellwig <[email protected]>
Quoted 2 lines · Ming Lei
bio_init()clears bio instance, so the bvec index has to be set afterbio_init(), otherwisebio->bi_io_vecmay be leaked.
Applied, thanks.
Signature · 1 line
Jens Axboe