Patchwork lib: fwts_microcode: fix leak of allocated microcode buffer

login
register
mail settings
Submitter Colin King
Date May 6, 2013, 9:50 p.m.
Message ID <1367877006-16912-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241798/
State Accepted
Headers show

Comments

Colin King - May 6, 2013, 9:50 p.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997340, Resource leak.

Need to free microcode buffer before we return.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_microcode.c | 1 +
 1 file changed, 1 insertion(+)
Alex Hung - May 7, 2013, 3:07 a.m.
On 05/07/2013 05:50 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997340, Resource leak.
>
> Need to free microcode buffer before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_microcode.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/src/lib/src/fwts_microcode.c b/src/lib/src/fwts_microcode.c
> index fb81c0c..0bcbc4b 100644
> --- a/src/lib/src/fwts_microcode.c
> +++ b/src/lib/src/fwts_microcode.c
> @@ -54,6 +54,7 @@ int fwts_update_microcode(fwts_framework *fw, const char *device, const char *fi
>
>   	if ((fp = fopen(filename, "r")) == NULL) {
>   		fwts_log_error(fw, "Cannot open source '%s'.", filename);
> +		free(microcode);
>   		return FWTS_ERROR;
>   	}
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 9, 2013, 6:38 a.m.
On Tue, May 7, 2013 at 5:50 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997340, Resource leak.
>
> Need to free microcode buffer before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_microcode.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/lib/src/fwts_microcode.c b/src/lib/src/fwts_microcode.c
> index fb81c0c..0bcbc4b 100644
> --- a/src/lib/src/fwts_microcode.c
> +++ b/src/lib/src/fwts_microcode.c
> @@ -54,6 +54,7 @@ int fwts_update_microcode(fwts_framework *fw, const char *device, const char *fi
>
>         if ((fp = fopen(filename, "r")) == NULL) {
>                 fwts_log_error(fw, "Cannot open source '%s'.", filename);
> +               free(microcode);
>                 return FWTS_ERROR;
>         }
>
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_microcode.c b/src/lib/src/fwts_microcode.c
index fb81c0c..0bcbc4b 100644
--- a/src/lib/src/fwts_microcode.c
+++ b/src/lib/src/fwts_microcode.c
@@ -54,6 +54,7 @@  int fwts_update_microcode(fwts_framework *fw, const char *device, const char *fi
 
 	if ((fp = fopen(filename, "r")) == NULL) {
 		fwts_log_error(fw, "Cannot open source '%s'.", filename);
+		free(microcode);
 		return FWTS_ERROR;
 	}