Skip to content

Commit de9f00d

Browse files
committed
md/raid1: fix memory leak in raid1_run() if no active rdev
JIRA: https://issues.redhat.com/browse/RHEL-83988 commit 5fbcf76 Author: Zheng Qixing <[email protected]> Date: Sat Feb 15 10:01:37 2025 +0800 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]> Signed-off-by: Nigel Croxon <[email protected]>
1 parent 2eaeac5 commit de9f00d

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
@@ -46,6 +46,7 @@
4646

4747
static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
4848
static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
49+
static void raid1_free(struct mddev *mddev, void *priv);
4950

5051
#define RAID_1_10_NAME "raid1"
5152
#include "raid1-10.c"
@@ -3252,8 +3253,11 @@ static int raid1_run(struct mddev *mddev)
32523253

32533254
if (!mddev_is_dm(mddev)) {
32543255
ret = raid1_set_limits(mddev);
3255-
if (ret)
3256+
if (ret) {
3257+
if (!mddev->private)
3258+
raid1_free(mddev, conf);
32563259
return ret;
3260+
}
32573261
}
32583262

32593263
mddev->degraded = 0;
@@ -3267,6 +3271,8 @@ static int raid1_run(struct mddev *mddev)
32673271
*/
32683272
if (conf->raid_disks - mddev->degraded < 1) {
32693273
md_unregister_thread(mddev, &conf->thread);
3274+
if (!mddev->private)
3275+
raid1_free(mddev, conf);
32703276
return -EINVAL;
32713277
}
32723278

0 commit comments

Comments
 (0)