Patchwork cpu: maxfreq: fix leak of cpuinfo

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

Comments

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

Coverity CID #997351, Resource leak.

Need to free cpuinfo before we return.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/maxfreq/maxfreq.c | 1 +
 1 file changed, 1 insertion(+)
Alex Hung - May 7, 2013, 3:06 a.m.
On 05/07/2013 05:38 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997351, Resource leak.
>
> Need to free cpuinfo before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/maxfreq/maxfreq.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
> index 87df364..b6fa38c 100644
> --- a/src/cpu/maxfreq/maxfreq.c
> +++ b/src/cpu/maxfreq/maxfreq.c
> @@ -81,6 +81,7 @@ static int maxfreq_test1(fwts_framework *fw)
>
>   	if ((cpufreq = calloc(cpus, sizeof(double))) == NULL) {
>   		fwts_log_error(fw, "Cannot create cpu frequency array.");
> +		fwts_list_free(cpuinfo, free);
>   		return FWTS_ERROR;
>   	}
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 9, 2013, 6:37 a.m.
On Tue, May 7, 2013 at 5:38 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997351, Resource leak.
>
> Need to free cpuinfo before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/maxfreq/maxfreq.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
> index 87df364..b6fa38c 100644
> --- a/src/cpu/maxfreq/maxfreq.c
> +++ b/src/cpu/maxfreq/maxfreq.c
> @@ -81,6 +81,7 @@ static int maxfreq_test1(fwts_framework *fw)
>
>         if ((cpufreq = calloc(cpus, sizeof(double))) == NULL) {
>                 fwts_log_error(fw, "Cannot create cpu frequency array.");
> +               fwts_list_free(cpuinfo, free);
>                 return FWTS_ERROR;
>         }
>
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
index 87df364..b6fa38c 100644
--- a/src/cpu/maxfreq/maxfreq.c
+++ b/src/cpu/maxfreq/maxfreq.c
@@ -81,6 +81,7 @@  static int maxfreq_test1(fwts_framework *fw)
 
 	if ((cpufreq = calloc(cpus, sizeof(double))) == NULL) {
 		fwts_log_error(fw, "Cannot create cpu frequency array.");
+		fwts_list_free(cpuinfo, free);
 		return FWTS_ERROR;
 	}