diff mbox series

[5/5] get_vd_num_of_subarray: fix memleak

Message ID f1bee99f-a9b0-0e58-36fb-e5eee110dcc9@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:51 a.m. UTC
sra = sysfs_read() should be free before return in
get_vd_num_of_subarray()

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 super-ddf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Mariusz Tkaczyk May 31, 2022, 8:11 a.m. UTC | #1
On Tue, 31 May 2022 14:51:13 +0800
Wu Guanghao <wuguanghao3@huawei.com> wrote:

> sra = sysfs_read() should be free before return in
> get_vd_num_of_subarray()
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>  super-ddf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/super-ddf.c b/super-ddf.c
> index 8cda23a7..827e4ae7 100644
> --- a/super-ddf.c
> +++ b/super-ddf.c
> @@ -1599,15 +1599,20 @@ static unsigned int get_vd_num_of_subarray(struct
> supertype *st) sra = sysfs_read(-1, st->devnm, GET_VERSION);
>  	if (!sra || sra->array.major_version != -1 ||
>  	    sra->array.minor_version != -2 ||
> -	    !is_subarray(sra->text_version))
> +	    !is_subarray(sra->text_version)) {
> +		if (sra)
> +			sysfs_free(sra);
>  		return DDF_NOTFOUND;
> +	}
> 
>  	sub = strchr(sra->text_version + 1, '/');
>  	if (sub != NULL)
>  		vcnum = strtoul(sub + 1, &end, 10);
>  	if (sub == NULL || *sub == '\0' || *end != '\0' ||
> -	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries))
> +	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) {
> +		sysfs_free(sra);
>  		return DDF_NOTFOUND;
> +	}
> 
>  	return vcnum;
>  }

Acked-by:mariusz.tkaczyk@linux.intel.com
Paul Menzel May 31, 2022, 8:25 a.m. UTC | #2
Dear Mariusz,


Am 31.05.22 um 10:11 schrieb Mariusz Tkaczyk:
> On Tue, 31 May 2022 14:51:13 +0800 Wu Guanghao wrote:
> 
>> sra = sysfs_read() should be free before return in
>> get_vd_num_of_subarray()
>>
>> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
>> ---
>>   super-ddf.c | 9 +++++++--
>>   1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/super-ddf.c b/super-ddf.c
>> index 8cda23a7..827e4ae7 100644
>> --- a/super-ddf.c
>> +++ b/super-ddf.c
>> @@ -1599,15 +1599,20 @@ static unsigned int get_vd_num_of_subarray(struct
>> supertype *st) sra = sysfs_read(-1, st->devnm, GET_VERSION);
>>   	if (!sra || sra->array.major_version != -1 ||
>>   	    sra->array.minor_version != -2 ||
>> -	    !is_subarray(sra->text_version))
>> +	    !is_subarray(sra->text_version)) {
>> +		if (sra)
>> +			sysfs_free(sra);
>>   		return DDF_NOTFOUND;
>> +	}
>>
>>   	sub = strchr(sra->text_version + 1, '/');
>>   	if (sub != NULL)
>>   		vcnum = strtoul(sub + 1, &end, 10);
>>   	if (sub == NULL || *sub == '\0' || *end != '\0' ||
>> -	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries))
>> +	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) {
>> +		sysfs_free(sra);
>>   		return DDF_NOTFOUND;
>> +	}
>>
>>   	return vcnum;
>>   }
> 
> Acked-by:mariusz.tkaczyk@linux.intel.com

Thank you for your review. The common format is:

Acked-by: Name <address>


Kind regards,

Paul
Mariusz Tkaczyk June 7, 2022, 6:32 a.m. UTC | #3
On Tue, 31 May 2022 10:25:31 +0200
Paul Menzel <pmenzel@molgen.mpg.de> wrote:

> Dear Mariusz,
> 
> 
> Am 31.05.22 um 10:11 schrieb Mariusz Tkaczyk:
> > On Tue, 31 May 2022 14:51:13 +0800 Wu Guanghao wrote:
> >   
> >> sra = sysfs_read() should be free before return in
> >> get_vd_num_of_subarray()
> >>
> >> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> >> ---
> >>   super-ddf.c | 9 +++++++--
> >>   1 file changed, 7 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/super-ddf.c b/super-ddf.c
> >> index 8cda23a7..827e4ae7 100644
> >> --- a/super-ddf.c
> >> +++ b/super-ddf.c
> >> @@ -1599,15 +1599,20 @@ static unsigned int get_vd_num_of_subarray(struct
> >> supertype *st) sra = sysfs_read(-1, st->devnm, GET_VERSION);
> >>   	if (!sra || sra->array.major_version != -1 ||
> >>   	    sra->array.minor_version != -2 ||
> >> -	    !is_subarray(sra->text_version))
> >> +	    !is_subarray(sra->text_version)) {
> >> +		if (sra)
> >> +			sysfs_free(sra);
> >>   		return DDF_NOTFOUND;
> >> +	}
> >>
> >>   	sub = strchr(sra->text_version + 1, '/');
> >>   	if (sub != NULL)
> >>   		vcnum = strtoul(sub + 1, &end, 10);
> >>   	if (sub == NULL || *sub == '\0' || *end != '\0' ||
> >> -	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries))
> >> +	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) {
> >> +		sysfs_free(sra);
> >>   		return DDF_NOTFOUND;
> >> +	}
> >>
> >>   	return vcnum;
> >>   }  
> > 
> > Acked-by:mariusz.tkaczyk@linux.intel.com  
> 
> Thank you for your review. The common format is:
> 
> Acked-by: Name <address>
> 
> 
Hi Paul,
Thanks, fixed.

Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
diff mbox series

Patch

diff --git a/super-ddf.c b/super-ddf.c
index 8cda23a7..827e4ae7 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -1599,15 +1599,20 @@  static unsigned int get_vd_num_of_subarray(struct supertype *st)
 	sra = sysfs_read(-1, st->devnm, GET_VERSION);
 	if (!sra || sra->array.major_version != -1 ||
 	    sra->array.minor_version != -2 ||
-	    !is_subarray(sra->text_version))
+	    !is_subarray(sra->text_version)) {
+		if (sra)
+			sysfs_free(sra);
 		return DDF_NOTFOUND;
+	}

 	sub = strchr(sra->text_version + 1, '/');
 	if (sub != NULL)
 		vcnum = strtoul(sub + 1, &end, 10);
 	if (sub == NULL || *sub == '\0' || *end != '\0' ||
-	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries))
+	    vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) {
+		sysfs_free(sra);
 		return DDF_NOTFOUND;
+	}

 	return vcnum;
 }