Skip to contentSkip to conversation

md/raid10:Memleak fix if allocate rep1_bio failed in function want_replacement().

PATCH In review majianpeng 2 participants 2 messages Apr 16, 2012 – Apr 17, 2012 MD RAID

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 1/1 md/raid10:Memleak fix if allocate rep1_bio failed in function want_replacement().

From cb391c87d24a32b211d9f0a9df942987bf8e0ac4 Mon Sep 17 00:00:00 2001
From: majianpeng <[email protected]>
Date: Mon, 16 Apr 2012 19:19:53 +0800
Subject: [PATCH] md/raid10:Memleak fix if allocate rep1_bio failed in
function want_replacement().
Reported by kmemleak.

---
 drivers/md/raid10.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/md/raid10.c +4 -3
index c8dbb84..19e9af1 100644
@@ -165,10 +165,11 @@ out_free_pages:
 	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);
 	}
Signature · 6 lines
1.7.5.4

 				
--------------
majianpeng
2012-04-16
#1 lore raw
Quoted 6 lines · On Mon, 16 Apr 2012 19:24:13 +0800 "majianpeng" <[email protected]> wrote:
Quoted 1 line

From cb391c87d24a32b211d9f0a9df942987bf8e0ac4 Mon Sep 17 00:00:00 2001

From: majianpeng <[email protected]>
Date: Mon, 16 Apr 2012 19:19:53 +0800
Subject: [PATCH] md/raid10:Memleak fix if allocate rep1_bio failed in
function want_replacement().
Reported by kmemleak.

Please try to make the description a bit easier to read. The first line should be a brief summary of the problem or fix.

Details come afterwards.

I have change it to the following and applied.

Thanks,
NeilBrown

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.

Quoted 25 lines
---
 drivers/md/raid10.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/md/raid10.c +4 -3
index c8dbb84..19e9af1 100644
@@ -165,10 +165,11 @@ out_free_pages:
 	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);
 	}