diff mbox series

uefirtvariable: fix memory leak

Message ID 20210514080010.9278-1-ivan.hu@canonical.com
State Accepted
Headers show
Series uefirtvariable: fix memory leak | expand

Commit Message

Ivan Hu May 14, 2021, 8 a.m. UTC
Also add void for the ioctl which is intentional ignore return for
deleting variable.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Colin Ian King May 14, 2021, 8:07 a.m. UTC | #1
On 14/05/2021 09:00, Ivan Hu wrote:
> Also add void for the ioctl which is intentional ignore return for
> deleting variable.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index b756ac96..f5aaa5fb 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -2223,7 +2223,7 @@ static int uefirtvariable_test9(fwts_framework *fw)
>  	/* delete the variable which was set */
>  	setvariable.DataSize = 0;
>  	status = ~0ULL;
> -	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +	(void)ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	variablename = malloc(sizeof(uint16_t) * variablenamesize);
>  	if (!variablename) {
> @@ -2300,6 +2300,9 @@ static int uefirtvariable_test9(fwts_framework *fw)
>  	} else
>  		fwts_skipped(fw, "QueryVarInfo runtime service supported, skip test.");
>  
> +	if (variablename)
> +		free(variablename);
> +
>  	return FWTS_OK;
>  }
>  
> 

Thanks Ivan.

Acked-by: Colin Ian King <colin.king@canonical.com>
Colin Ian King May 14, 2021, 8:13 a.m. UTC | #2
On 14/05/2021 09:07, Colin Ian King wrote:
> On 14/05/2021 09:00, Ivan Hu wrote:
>> Also add void for the ioctl which is intentional ignore return for
>> deleting variable.
>>
>> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
>> ---
>>  src/uefi/uefirtvariable/uefirtvariable.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
>> index b756ac96..f5aaa5fb 100644
>> --- a/src/uefi/uefirtvariable/uefirtvariable.c
>> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
>> @@ -2223,7 +2223,7 @@ static int uefirtvariable_test9(fwts_framework *fw)
>>  	/* delete the variable which was set */
>>  	setvariable.DataSize = 0;
>>  	status = ~0ULL;
>> -	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>> +	(void)ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>>  
>>  	variablename = malloc(sizeof(uint16_t) * variablenamesize);
>>  	if (!variablename) {
>> @@ -2300,6 +2300,9 @@ static int uefirtvariable_test9(fwts_framework *fw)
>>  	} else
>>  		fwts_skipped(fw, "QueryVarInfo runtime service supported, skip test.");
>>  
>> +	if (variablename)
>> +		free(variablename);

Actually free of a NULL variablename is OK,so the if () is not strictly
required, but lets leave that in as it shows intent.

>> +
>>  	return FWTS_OK;
>>  }
>>  
>>
> 
> Thanks Ivan.
> 
> Acked-by: Colin Ian King <colin.king@canonical.com>
>
Alex Hung May 14, 2021, 11:39 p.m. UTC | #3
On 2021-05-14 2:00 a.m., Ivan Hu wrote:
> Also add void for the ioctl which is intentional ignore return for
> deleting variable.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index b756ac96..f5aaa5fb 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -2223,7 +2223,7 @@ static int uefirtvariable_test9(fwts_framework *fw)
>  	/* delete the variable which was set */
>  	setvariable.DataSize = 0;
>  	status = ~0ULL;
> -	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +	(void)ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	variablename = malloc(sizeof(uint16_t) * variablenamesize);
>  	if (!variablename) {
> @@ -2300,6 +2300,9 @@ static int uefirtvariable_test9(fwts_framework *fw)
>  	} else
>  		fwts_skipped(fw, "QueryVarInfo runtime service supported, skip test.");
>  
> +	if (variablename)
> +		free(variablename);
> +
>  	return FWTS_OK;
>  }
>  
> 

Acked-by: Alex Hung <alex.hung@canonical.cmo>
diff mbox series

Patch

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index b756ac96..f5aaa5fb 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -2223,7 +2223,7 @@  static int uefirtvariable_test9(fwts_framework *fw)
 	/* delete the variable which was set */
 	setvariable.DataSize = 0;
 	status = ~0ULL;
-	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+	(void)ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	variablename = malloc(sizeof(uint16_t) * variablenamesize);
 	if (!variablename) {
@@ -2300,6 +2300,9 @@  static int uefirtvariable_test9(fwts_framework *fw)
 	} else
 		fwts_skipped(fw, "QueryVarInfo runtime service supported, skip test.");
 
+	if (variablename)
+		free(variablename);
+
 	return FWTS_OK;
 }