diff mbox series

[1/5] parse_layout_faulty: fix memleak

Message ID bd8d7da6-83e7-da9b-1647-d95220a535e7@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 May 31, 2022, 6:49 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 | 1 +
 1 file changed, 1 insertion(+)

Comments

Mariusz Tkaczyk May 31, 2022, 7:36 a.m. UTC | #1
On Tue, 31 May 2022 14:49:17 +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 | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/util.c b/util.c
> index cc94f96e..da18a68d 100644
> --- a/util.c
> +++ b/util.c
> @@ -429,6 +429,7 @@ int parse_layout_faulty(char *layout)
>  	int mode;
>  	m[ln] = 0;
>  	mode = map_name(faultylayout, m);
> +	free(m);
>  	if (mode == UnSet)
>  		return -1;
> 

Hi,
Please add empty lines to separate declarations and not related code
sections.

Thanks,
Mariusz
Wu Guanghao June 7, 2022, 7:24 a.m. UTC | #2
在 2022/5/31 15:36, Mariusz Tkaczyk 写道:
> On Tue, 31 May 2022 14:49:17 +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 | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/util.c b/util.c
>> index cc94f96e..da18a68d 100644
>> --- a/util.c
>> +++ b/util.c
>> @@ -429,6 +429,7 @@ int parse_layout_faulty(char *layout)
>>  	int mode;
>>  	m[ln] = 0;
>>  	mode = map_name(faultylayout, m);
>> +	free(m);
>>  	if (mode == UnSet)
>>  		return -1;
>>
> 
> Hi,
> Please add empty lines to separate declarations and not related code
> sections.
> 

Thanks for your reply. I will be modified in PATCH v2.

> Thanks,
> Mariusz
> 
> .
>
diff mbox series

Patch

diff --git a/util.c b/util.c
index cc94f96e..da18a68d 100644
--- a/util.c
+++ b/util.c
@@ -429,6 +429,7 @@  int parse_layout_faulty(char *layout)
 	int mode;
 	m[ln] = 0;
 	mode = map_name(faultylayout, m);
+	free(m);
 	if (mode == UnSet)
 		return -1;