mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minfei Huang <mnfhuang@gmail.com>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	mhuang@redhat.com, Minfei Huang <mnfhuang@gmail.com>
Subject: [PATCH 2/2] bio: Free own bvec before assigning the source bio's bvec
Date: Fri, 18 Dec 2015 23:02:32 +0800	[thread overview]
Message-ID: <1450450952-18565-2-git-send-email-mnfhuang@gmail.com> (raw)
In-Reply-To: <1450450952-18565-1-git-send-email-mnfhuang@gmail.com>

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


  reply	other threads:[~2015-12-18 15:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-18 15:02 [PATCH 1/2] bio: Remove the incorrect test for idx in __bio_clone_fast Minfei Huang
2015-12-18 15:02 ` Minfei Huang [this message]
2015-12-18 15:29   ` [PATCH 2/2] bio: Free own bvec before assigning the source bio's bvec Minfei Huang
2015-12-18 15:31 ` [PATCH 1/2] bio: Remove the incorrect test for idx in __bio_clone_fast Minfei Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450450952-18565-2-git-send-email-mnfhuang@gmail.com \
    --to=mnfhuang@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhuang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome