md/raid10: fix memleak of md thread
authorYu Kuai <yukuai3@huawei.com>
Fri, 10 Mar 2023 07:38:55 +0000 (15:38 +0800)
committerSong Liu <song@kernel.org>
Fri, 14 Apr 2023 07:42:03 +0000 (00:42 -0700)
In raid10_run(), if setup_conf() succeed and raid10_run() failed before
setting 'mddev->thread', then in the error path 'conf->thread' is not
freed.

Fix the problem by setting 'mddev->thread' right after setup_conf().

Fixes: 43a521238aca ("md-cluster: choose correct label when clustered layout is not supported")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230310073855.1337560-7-yukuai1@huaweicloud.com
drivers/md/raid10.c

index befa477..375ed73 100644 (file)
@@ -4150,6 +4150,9 @@ static int raid10_run(struct mddev *mddev)
        if (!conf)
                goto out;
 
+       mddev->thread = conf->thread;
+       conf->thread = NULL;
+
        if (mddev_is_clustered(conf->mddev)) {
                int fc, fo;
 
@@ -4162,9 +4165,6 @@ static int raid10_run(struct mddev *mddev)
                }
        }
 
-       mddev->thread = conf->thread;
-       conf->thread = NULL;
-
        if (mddev->queue) {
                blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
                blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);