Skip to contentSkip to conversation

fix memory leak for bitmap

PATCH In review Zhao Heming 3 participants 4 messages Sep 27, 2020 – Oct 8, 2020 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix memory leak for bitmap

current code doesn't free temporary bitmap memory.

---
 drivers/md/md-bitmap.c  | 1 +
 drivers/md/md-cluster.c | 1 +
 2 files changed, 2 insertions(+)
drivers/md/md-bitmap.c +1 -0
index b10c519..593fe15 100644
@@ -2012,6 +2012,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
 	md_bitmap_unplug(mddev->bitmap);
 	*low = lo;
 	*high = hi;
+	md_bitmap_free(bitmap);
 
 	return rv;
 }
drivers/md/md-cluster.c +1 -0
index d50737e..afbbc55 100644
@@ -1166,6 +1166,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
 			 * can't resize bitmap
 			 */
 			goto out;
+		md_bitmap_free(bitmap);
 	}
 
 	return 0;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 25 lines · Zhao Heming

current code doesn't free temporary bitmap memory.

---
  drivers/md/md-bitmap.c  | 1 +
  drivers/md/md-cluster.c | 1 +
  2 files changed, 2 insertions(+)
drivers/md/md-bitmap.c +1 -0
index b10c519..593fe15 100644
@@ -2012,6 +2012,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
  	md_bitmap_unplug(mddev->bitmap);
  	*low = lo;
  	*high = hi;
+	md_bitmap_free(bitmap);
 
  	return rv;
  }
drivers/md/md-cluster.c +0 -0
index d50737e..afbbc55 100644

drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1172

Quoted 7 lines
drivers/md/md-cluster.c +1 -0
@@ -1166,6 +1166,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
  			 * can't resize bitmap
  			 */
  			goto out;
+		md_bitmap_free(bitmap);
  	}
 
  	return 0;

I'd prefer add a comment for get_bitmap_from_slot to mention it's caller need to free bitmap.

Thanks,
Guoqing

maintainer
#2 lore raw
Quoted 35 lines · Guoqing Jiang
Quoted 31 lines · Zhao Heming

current code doesn't free temporary bitmap memory.

---
  drivers/md/md-bitmap.c  | 1 +
  drivers/md/md-cluster.c | 1 +
  2 files changed, 2 insertions(+)
drivers/md/md-bitmap.c +1 -0
index b10c519..593fe15 100644
@@ -2012,6 +2012,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
      md_bitmap_unplug(mddev->bitmap);
      *low = lo;
      *high = hi;
+     md_bitmap_free(bitmap);
 
      return rv;
  }
drivers/md/md-cluster.c +1 -0
index d50737e..afbbc55 100644
@@ -1166,6 +1166,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
                       * can't resize bitmap
                       */
                      goto out;
+             md_bitmap_free(bitmap);
      }
 
Quoted 5 lines

drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1172

Quoted 1 line
drivers/md/md-cluster.c +0 -0
      return 0;

I'd prefer add a comment for get_bitmap_from_slot to mention it's caller need to
free bitmap.

I added comment to the patch with Guoqing's "Suggested-by" tag, and applied it to md-next. I also made some changes to the commit log of all 3 patches from Heming.

Herming, for future patches, please prefix the subject with "md:" or "md/bitmap".

Thanks,
Song

#3 lore raw

Hello Song & Guoqing,

Thank you for your review.
I will take your advises & take more attention on later.

Quoted 53 lines · Song Liu
Quoted 35 lines · Guoqing Jiang
Quoted 31 lines · Zhao Heming

current code doesn't free temporary bitmap memory.

---
   drivers/md/md-bitmap.c  | 1 +
   drivers/md/md-cluster.c | 1 +
   2 files changed, 2 insertions(+)
drivers/md/md-bitmap.c +1 -0
index b10c519..593fe15 100644
@@ -2012,6 +2012,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
       md_bitmap_unplug(mddev->bitmap);
       *low = lo;
       *high = hi;
+     md_bitmap_free(bitmap);
 
       return rv;
   }
drivers/md/md-cluster.c +1 -0
index d50737e..afbbc55 100644
@@ -1166,6 +1166,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
                        * can't resize bitmap
                        */
                       goto out;
+             md_bitmap_free(bitmap);
       }
 
Quoted 5 lines

drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1172

Quoted 1 line
drivers/md/md-cluster.c +0 -0
       return 0;

I'd prefer add a comment for get_bitmap_from_slot to mention it's caller need to
free bitmap.

I added comment to the patch with Guoqing's "Suggested-by" tag, and applied it to md-next. I also made some changes to the commit log of all 3 patches from Heming.

Herming, for future patches, please prefix the subject with "md:" or "md/bitmap".

Thanks,
Song