]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: modify the order of free_super_xxx() to avoid memory leak
authorWu Guanghao <wuguanghao3@huawei.com>
Tue, 14 Oct 2025 02:23:46 +0000 (10:23 +0800)
committerXiaoNi87 <xni@redhat.com>
Thu, 16 Oct 2025 14:02:02 +0000 (22:02 +0800)
free_super_xx() should be executed at the load_super_xx() entry.
When there are additional checks, it may lead to supertype not being
released, resulting in a memory leak.

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
super-ddf.c
super-intel.c

index f4621720643747fb3289b98e197088c19bd712ae..7b38f91251342726912fcf54472d55832167800b 100644 (file)
@@ -1324,6 +1324,8 @@ static int load_super_ddf(struct supertype *st, int fd,
        struct ddf_super *super;
        int rv;
 
+       free_super_ddf(st);
+
        if (get_dev_size(fd, devname, &dsize) == 0)
                return 1;
 
@@ -1345,8 +1347,6 @@ static int load_super_ddf(struct supertype *st, int fd,
                return 1;
        }
 
-       free_super_ddf(st);
-
        if (posix_memalign((void**)&super, 512, sizeof(*super))!= 0) {
                pr_err("malloc of %zu failed.\n",
                        sizeof(*super));
index 7162327ecdf2db9b877d38da6c8fdf8970ac864d..5a4a2eb1c949512b10493fd8872114958c493dbb 100644 (file)
@@ -5471,12 +5471,12 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname)
        int rv;
        int retry;
 
+       free_super_imsm(st);
+
        if (test_partition(fd))
                /* IMSM not allowed on partitions */
                return 1;
 
-       free_super_imsm(st);
-
        super = alloc_super();
        if (!super)
                return 1;