Patchwork lib: fwts_keymap: free keymap_list on error

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

Comments

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

Coverity CID #997344, Resource leak.

Need to free keymap_list before we return

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_keymap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Alex Hung - May 7, 2013, 3:29 a.m.
On 05/07/2013 05:59 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997344, Resource leak.
>
> Need to free keymap_list before we return
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_keymap.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_keymap.c b/src/lib/src/fwts_keymap.c
> index 71800fc..646cdfa 100644
> --- a/src/lib/src/fwts_keymap.c
> +++ b/src/lib/src/fwts_keymap.c
> @@ -62,8 +62,10 @@ fwts_list *fwts_keymap_load(const char *machine)
>
>   	snprintf(path, sizeof(path), "%s/%s", FWTS_KEYMAP_PATH, machine);
>
> -	if ((fp = fopen(path, "r")) == NULL)
> +	if ((fp = fopen(path, "r")) == NULL) {
> +		fwts_keymap_free(keymap_list);
>   		return NULL;
> +	}
>
>   	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
>   		fwts_keycode *key;
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 10, 2013, 8:16 a.m.
On 05/07/2013 05:59 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997344, Resource leak.
>
> Need to free keymap_list before we return
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_keymap.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_keymap.c b/src/lib/src/fwts_keymap.c
> index 71800fc..646cdfa 100644
> --- a/src/lib/src/fwts_keymap.c
> +++ b/src/lib/src/fwts_keymap.c
> @@ -62,8 +62,10 @@ fwts_list *fwts_keymap_load(const char *machine)
>
>   	snprintf(path, sizeof(path), "%s/%s", FWTS_KEYMAP_PATH, machine);
>
> -	if ((fp = fopen(path, "r")) == NULL)
> +	if ((fp = fopen(path, "r")) == NULL) {
> +		fwts_keymap_free(keymap_list);
>   		return NULL;
> +	}
>
>   	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
>   		fwts_keycode *key;
>

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

Patch

diff --git a/src/lib/src/fwts_keymap.c b/src/lib/src/fwts_keymap.c
index 71800fc..646cdfa 100644
--- a/src/lib/src/fwts_keymap.c
+++ b/src/lib/src/fwts_keymap.c
@@ -62,8 +62,10 @@  fwts_list *fwts_keymap_load(const char *machine)
 
 	snprintf(path, sizeof(path), "%s/%s", FWTS_KEYMAP_PATH, machine);
 
-	if ((fp = fopen(path, "r")) == NULL)
+	if ((fp = fopen(path, "r")) == NULL) {
+		fwts_keymap_free(keymap_list);
 		return NULL;
+	}
 
 	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
 		fwts_keycode *key;