Skip to content

Commit 5fbcf76

Browse files
Zheng QixingYu Kuai
authored andcommitted
md/raid1: fix memory leak in raid1_run() if no active rdev
When `raid1_set_limits()` fails or when the array has no active `rdev`, the allocated memory for `conf` is not properly freed. Add raid1_free() call to properly free the conf in error path. Fixes: 799af94 ("md/raid1: don't free conf on raid0_run failure") Signed-off-by: Zheng Qixing <[email protected]> Link: https://lore.kernel.org/linux-raid/[email protected] Singed-off-by: Yu Kuai <[email protected]>
1 parent 4b10a3b commit 5fbcf76

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/md/raid1.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
4747
static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
48+
static void raid1_free(struct mddev *mddev, void *priv);
4849

4950
#define RAID_1_10_NAME "raid1"
5051
#include "raid1-10.c"
@@ -3258,8 +3259,11 @@ static int raid1_run(struct mddev *mddev)
32583259

32593260
if (!mddev_is_dm(mddev)) {
32603261
ret = raid1_set_limits(mddev);
3261-
if (ret)
3262+
if (ret) {
3263+
if (!mddev->private)
3264+
raid1_free(mddev, conf);
32623265
return ret;
3266+
}
32633267
}
32643268

32653269
mddev->degraded = 0;
@@ -3273,6 +3277,8 @@ static int raid1_run(struct mddev *mddev)
32733277
*/
32743278
if (conf->raid_disks - mddev->degraded < 1) {
32753279
md_unregister_thread(mddev, &conf->thread);
3280+
if (!mddev->private)
3281+
raid1_free(mddev, conf);
32763282
return -EINVAL;
32773283
}
32783284

0 commit comments

Comments
 (0)