Patchwork lib: fwts_memorymap: free klog on error

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

Comments

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

Coverity CID #997341, Resource leak.

Need to free klog list before we return.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_memorymap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Alex Hung - May 7, 2013, 3:27 a.m.
On 05/07/2013 05:53 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997341, Resource leak.
>
> Need to free klog list before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_memorymap.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
> index 2988e5b..6e8bc1e 100644
> --- a/src/lib/src/fwts_memorymap.c
> +++ b/src/lib/src/fwts_memorymap.c
> @@ -233,8 +233,10 @@ fwts_list *fwts_memory_map_table_load_from_klog(fwts_framework *fw)
>   	if ((klog = fwts_klog_read()) == NULL)
>   		return NULL;
>
> -	if ((memory_map_list = fwts_list_new()) == NULL)
> +	if ((memory_map_list = fwts_list_new()) == NULL) {
> +		fwts_klog_free(klog);
>   		return NULL;
> +	}
>
>   	fwts_list_iterate(klog, fwts_memory_map_dmesg_info, memory_map_list);
>   	fwts_klog_free(klog);
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 10, 2013, 8:14 a.m.
On 05/07/2013 05:53 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997341, Resource leak.
>
> Need to free klog list before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_memorymap.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
> index 2988e5b..6e8bc1e 100644
> --- a/src/lib/src/fwts_memorymap.c
> +++ b/src/lib/src/fwts_memorymap.c
> @@ -233,8 +233,10 @@ fwts_list *fwts_memory_map_table_load_from_klog(fwts_framework *fw)
>   	if ((klog = fwts_klog_read()) == NULL)
>   		return NULL;
>
> -	if ((memory_map_list = fwts_list_new()) == NULL)
> +	if ((memory_map_list = fwts_list_new()) == NULL) {
> +		fwts_klog_free(klog);
>   		return NULL;
> +	}
>
>   	fwts_list_iterate(klog, fwts_memory_map_dmesg_info, memory_map_list);
>   	fwts_klog_free(klog);
>

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

Patch

diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
index 2988e5b..6e8bc1e 100644
--- a/src/lib/src/fwts_memorymap.c
+++ b/src/lib/src/fwts_memorymap.c
@@ -233,8 +233,10 @@  fwts_list *fwts_memory_map_table_load_from_klog(fwts_framework *fw)
 	if ((klog = fwts_klog_read()) == NULL)
 		return NULL;
 
-	if ((memory_map_list = fwts_list_new()) == NULL)
+	if ((memory_map_list = fwts_list_new()) == NULL) {
+		fwts_klog_free(klog);
 		return NULL;
+	}
 
 	fwts_list_iterate(klog, fwts_memory_map_dmesg_info, memory_map_list);
 	fwts_klog_free(klog);