diff mbox series

uefi: uefirtvariable: fix a memory leak of variablename

Message ID 20200407174439.922624-1-colin.king@canonical.com
State Accepted
Headers show
Series uefi: uefirtvariable: fix a memory leak of variablename | expand

Commit Message

Colin Ian King April 7, 2020, 5:44 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

In the case where an ioctl fails the error handling currently
returns without freeing variablename. Fix this by setting ret
to FWTS_ERROR and falling through to the return path that
frees variable name and returns the error code.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Alex Hung April 7, 2020, 6:10 p.m. UTC | #1
On 2020-04-07 11:44 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> In the case where an ioctl fails the error handling currently
> returns without freeing variablename. Fix this by setting ret
> to FWTS_ERROR and falling through to the return path that
> frees variable name and returns the error code.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index 3986d1d3..fb993983 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -466,12 +466,11 @@ err_restore_env:
>  	status = ~0ULL;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> -
>  	if (ioret == -1) {
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> -		return FWTS_ERROR;
> +		ret = FWTS_ERROR;
>  	}
>  
>  	if (variablename)
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu April 8, 2020, 7:28 a.m. UTC | #2
On 4/8/20 1:44 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> In the case where an ioctl fails the error handling currently
> returns without freeing variablename. Fix this by setting ret
> to FWTS_ERROR and falling through to the return path that
> frees variable name and returns the error code.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index 3986d1d3..fb993983 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -466,12 +466,11 @@ err_restore_env:
>  	status = ~0ULL;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> -
>  	if (ioret == -1) {
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> -		return FWTS_ERROR;
> +		ret = FWTS_ERROR;
>  	}
>  
>  	if (variablename)
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index 3986d1d3..fb993983 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -466,12 +466,11 @@  err_restore_env:
 	status = ~0ULL;
 
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
-
 	if (ioret == -1) {
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
 			"Failed to delete variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
-		return FWTS_ERROR;
+		ret = FWTS_ERROR;
 	}
 
 	if (variablename)