diff mbox series

[1/5,v2] parse_layout_faulty: fix memleak

Message ID 19e8b467-a786-f42d-f07e-dfacae4f57c9@huawei.com (mailing list archive)
State Superseded, archived
Headers show
Series mdadm: fix memory leak and double free | expand

Commit Message

Wu Guanghao Aug. 2, 2022, 2:15 a.m. UTC
char *m is allocated by xstrdup but not free() before return, will cause
a memory leak

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 util.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.27.0

Comments

Coly Li Sept. 3, 2022, 8:26 a.m. UTC | #1
> 2022年8月2日 10:15,Wu Guanghao <wuguanghao3@huawei.com> 写道:
> 
> char *m is allocated by xstrdup but not free() before return, will cause
> a memory leak
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>

Acked-by: Coly Li <colyli@suse.de>

Thanks.

Coly Li

> ---
> util.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/util.c b/util.c
> index 38f0420e..2e0f1de7 100644
> --- a/util.c
> +++ b/util.c
> @@ -427,8 +427,11 @@ int parse_layout_faulty(char *layout)
>        int ln = strcspn(layout, "0123456789");
>        char *m = xstrdup(layout);
>        int mode;
> +
>        m[ln] = 0;
>        mode = map_name(faultylayout, m);
> +       free(m);
> +
>        if (mode == UnSet)
>                return -1;
> 
> --
> 2.27.0
diff mbox series

Patch

diff --git a/util.c b/util.c
index 38f0420e..2e0f1de7 100644
--- a/util.c
+++ b/util.c
@@ -427,8 +427,11 @@  int parse_layout_faulty(char *layout)
        int ln = strcspn(layout, "0123456789");
        char *m = xstrdup(layout);
        int mode;
+
        m[ln] = 0;
        mode = map_name(faultylayout, m);
+       free(m);
+
        if (mode == UnSet)
                return -1;