Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1294946

[PATCH 2/2] bio: Free own bvec before assigning the source bio's bvec

From Minfei Huang <mnfhuang@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 2/2] bio: Free own bvec before assigning the source bio's bvec
Date 2015-12-18 16:10 +0100
Message-ID <qH4Po-7gd-19@gated-at.bofh.it> (permalink)
References <qH4Po-7gd-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This is a memory leaking during splitting the bio by the caller
bio_clone_fast.

Clone bio may allocate its own bvec, if demanding bvec is more than
inline bvec in function bio_alloc_bioset.

bi_io_vec is assigned to the source bio's bvec directly without freeing
it firstly in function __bio_clone_fast.

To fix it, freeing the own bvec firstly before assigning the source
bio's bvec.

Signed-off-by: Minfei Huang <mnfhuang@gmail.com>
---
 block/bio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/bio.c b/block/bio.c
index 70d9814..b24fd6e 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -581,6 +581,10 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
 	bio_set_flag(bio, BIO_CLONED);
 	bio->bi_rw = bio_src->bi_rw;
 	bio->bi_iter = bio_src->bi_iter;
+
+	if (bio_flagged(bio, BIO_OWNS_VEC))
+		bvec_free(bio->bi_pool->bvec_pool,
+				bio->bi_io_vec, BIO_POOL_IDX(bio));
 	bio->bi_io_vec = bio_src->bi_io_vec;
 }
 EXPORT_SYMBOL(__bio_clone_fast);
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] bio: Remove the incorrect test for idx in __bio_clone_fast Minfei Huang <mnfhuang@gmail.com> - 2015-12-18 16:10 +0100
  [PATCH 2/2] bio: Free own bvec before assigning the source bio's bvec Minfei Huang <mnfhuang@gmail.com> - 2015-12-18 16:10 +0100
    Re: [PATCH 2/2] bio: Free own bvec before assigning the source bio's  bvec Minfei Huang <mnfhuang@gmail.com> - 2015-12-18 16:30 +0100
  Re: [PATCH 1/2] bio: Remove the incorrect test for idx in  __bio_clone_fast Minfei Huang <mnfhuang@gmail.com> - 2015-12-18 16:40 +0100

csiph-web