diff mbox series

[1/5,v2] parse_layout_faulty: fix memleak

Message ID 00ae6b42-b561-6542-0421-4ab8542d5d75@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Jes Sorensen
Headers show
Series mdadm: fix memory leak and double free | expand

Commit Message

Wu Guanghao June 9, 2022, 3:06 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>
---
 util.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.27.0

Comments

Mariusz Tkaczyk June 10, 2022, 9:13 a.m. UTC | #1
On Thu, 9 Jun 2022 11:06:13 +0800
Wu Guanghao <wuguanghao3@huawei.com> wrote:

> char *m is allocated by xstrdup but not free() before return, will cause
> a memory leak.
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>  util.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/util.c b/util.c
> index cc94f96e..46b04afb 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

Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Jes Sorensen July 28, 2022, 9:15 p.m. UTC | #2
On 6/8/22 23:06, Wu Guanghao wrote:
> char *m is allocated by xstrdup but not free() before return, will cause
> a memory leak.
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>  util.c | 3 +++
>  1 file changed, 3 insertions(+)

Hi Wu

This no longer seems to apply, would you mind rebasing and resending the
series?

Thanks,
Jes

> diff --git a/util.c b/util.c
> index cc94f96e..46b04afb 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
Wu Guanghao Aug. 1, 2022, 8:07 a.m. UTC | #3
在 2022/7/29 5:15, Jes Sorensen 写道:
> On 6/8/22 23:06, Wu Guanghao wrote:
>> char *m is allocated by xstrdup but not free() before return, will cause
>> a memory leak.
>>
>> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
>> ---
>>  util.c | 3 +++
>>  1 file changed, 3 insertions(+)
> 
> Hi Wu
> 
> This no longer seems to apply, would you mind rebasing and resending the
> series?
> 
> Thanks,
> Jes
OK, I will rebase and resend later.

Wu
> 
>> diff --git a/util.c b/util.c
>> index cc94f96e..46b04afb 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 cc94f96e..46b04afb 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;