md/bitmap: fix memory leak of temporary bitmap
authorZhao Heming <heming.zhao@suse.com>
Sun, 27 Sep 2020 05:40:13 +0000 (13:40 +0800)
committerSong Liu <songliubraving@fb.com>
Fri, 9 Oct 2020 05:37:39 +0000 (22:37 -0700)
Callers of get_bitmap_from_slot() are responsible to free the bitmap.

Suggested-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: Zhao Heming <heming.zhao@suse.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
drivers/md/md-bitmap.c
drivers/md/md-cluster.c

index b3f1310..200c5d0 100644 (file)
@@ -1950,6 +1950,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(md_bitmap_load);
 
+/* caller need to free returned bitmap with md_bitmap_free() */
 struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
 {
        int rv = 0;
@@ -2013,6 +2014,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;
 }
@@ -2616,4 +2618,3 @@ struct attribute_group md_bitmap_group = {
        .name = "bitmap",
        .attrs = md_bitmap_attrs,
 };
-
index 0580b51..4aaf482 100644 (file)
@@ -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;