From 5fdd2cf8265c6de0f190dea80cc4c50da8f31293 Mon Sep 17 00:00:00 2001 From: majianpeng Date: Tue, 22 May 2012 13:55:03 +1000 Subject: [PATCH] md/raid10: Fix memleak in r10buf_pool_alloc If the allocation of rep1_bio fails, we currently don't free the 'bio' of the same dev. Reported by kmemleak. Signed-off-by: majianpeng Signed-off-by: NeilBrown --- drivers/md/raid10.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index ec271ae4318f..fb9062b5022c 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -173,10 +173,11 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data) while (j--) for (i = 0; i < RESYNC_PAGES ; i++) safe_put_page(r10_bio->devs[j].bio->bi_io_vec[i].bv_page); - j = -1; + j = 0; out_free_bio: - while (++j < nalloc) { - bio_put(r10_bio->devs[j].bio); + for ( ; j < nalloc; j++) { + if (r10_bio->devs[j].bio) + bio_put(r10_bio->devs[j].bio); if (r10_bio->devs[j].repl_bio) bio_put(r10_bio->devs[j].repl_bio); } -- GitLab