lkml.org 
[lkml]   [2009]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] block: fix memory leak in bio_clone()
On Mon, Mar 09 2009, Li Zefan wrote:
> Jens Axboe wrote:
> > On Mon, Mar 09 2009, Li Zefan wrote:
> >> If bio_integrity_clone() fails, bio_clone() returns NULL without freeing
> >> the newly allocated bio.
> >>
> >> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> >> ---
> >> fs/bio.c | 4 +++-
> >> 1 files changed, 3 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/fs/bio.c b/fs/bio.c
> >> index 124b95c..896330e 100644
> >> --- a/fs/bio.c
> >> +++ b/fs/bio.c
> >> @@ -465,8 +465,10 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
> >>
> >> ret = bio_integrity_clone(b, bio, fs_bio_set);
> >>
> >> - if (ret < 0)
> >> + if (ret < 0) {
> >> + bio_put(bio);
> >> return NULL;
> >> + }
> >> }
> >>
> >> return b;
> >> -- 1.5.4.rc3
> >
> > Good spotting. But it looks like there are actually several problems
> > there. bio_integrity_clone() is mempool backed. Currently that ret < 0
> > can never trigger, since bio_integrity_clone() has hard-wired __GFP_WAIT
>
> Do you mean GFP_NOIO?

The __GFP_WAIT part of GFP_NOIO is the important bit :-)

> > as the mempool mask. So the leak will not occur, but it does mean that
> > it isn't honoring the gfp_mask passed in to bio_clone(), which is the
>
> I noticed there was a patch to do this, and seems you planed to merge
> it into .29?
>
> "[PATCH] Add gfp_mask to bio_integrity_clone()"
>
> http://lkml.org/lkml/2008/10/30/11

Hmm strange, apparently that never got queued up and I had forgotten all
about that issue until your email. I'll add it asap.

> > first bug. The second bug is that it should be using its own bioset, as
> > it is illegal to do multiple __GFP_WAIT allocations on a single mempool
> > and always expect progress.

That one still stands.

--
Jens Axboe



\
 
 \ /
  Last update: 2009-03-09 10:41    [W:0.053 / U:19.264 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site