Patchwork bios: mtrr: free mtrr_list on file open error

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

Comments

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

Free mtrr_list on file open error to fix resource leak bug.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/bios/mtrr/mtrr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Alex Hung - May 7, 2013, 3:43 a.m.
On 05/07/2013 06:20 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Free mtrr_list on file open error to fix resource leak bug.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/bios/mtrr/mtrr.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
> index 284d153..38f89fb 100644
> --- a/src/bios/mtrr/mtrr.c
> +++ b/src/bios/mtrr/mtrr.c
> @@ -88,8 +88,10 @@ static int get_mtrrs(void)
>   	if ((mtrr_list = fwts_list_new()) == NULL)
>   		return FWTS_ERROR;
>
> -	if ((fp = fopen("/proc/mtrr", "r")) == NULL)
> +	if ((fp = fopen("/proc/mtrr", "r")) == NULL) {
> +		fwts_list_free(mtrr_list, free);
>   		return FWTS_ERROR;
> +	}
>
>   	while (!feof(fp)) {
>   		char *ptr1, *ptr2;
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 10, 2013, 8:47 a.m.
On 05/07/2013 06:20 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Free mtrr_list on file open error to fix resource leak bug.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/bios/mtrr/mtrr.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
> index 284d153..38f89fb 100644
> --- a/src/bios/mtrr/mtrr.c
> +++ b/src/bios/mtrr/mtrr.c
> @@ -88,8 +88,10 @@ static int get_mtrrs(void)
>   	if ((mtrr_list = fwts_list_new()) == NULL)
>   		return FWTS_ERROR;
>
> -	if ((fp = fopen("/proc/mtrr", "r")) == NULL)
> +	if ((fp = fopen("/proc/mtrr", "r")) == NULL) {
> +		fwts_list_free(mtrr_list, free);
>   		return FWTS_ERROR;
> +	}
>
>   	while (!feof(fp)) {
>   		char *ptr1, *ptr2;
>

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

Patch

diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
index 284d153..38f89fb 100644
--- a/src/bios/mtrr/mtrr.c
+++ b/src/bios/mtrr/mtrr.c
@@ -88,8 +88,10 @@  static int get_mtrrs(void)
 	if ((mtrr_list = fwts_list_new()) == NULL)
 		return FWTS_ERROR;
 
-	if ((fp = fopen("/proc/mtrr", "r")) == NULL)
+	if ((fp = fopen("/proc/mtrr", "r")) == NULL) {
+		fwts_list_free(mtrr_list, free);
 		return FWTS_ERROR;
+	}
 
 	while (!feof(fp)) {
 		char *ptr1, *ptr2;