Patchwork cpu: maxfreq: free cpufreq on error

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

Comments

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

Coverity CID #997350, Resource leak.

Need to free cpufreq before we return.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/maxfreq/maxfreq.c | 2 ++
 1 file changed, 2 insertions(+)
Alex Hung - May 7, 2013, 3:46 a.m.
On 05/07/2013 06:23 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997350, Resource leak.
>
> Need to free cpufreq before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/maxfreq/maxfreq.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
> index b6fa38c..e8e6ffa 100644
> --- a/src/cpu/maxfreq/maxfreq.c
> +++ b/src/cpu/maxfreq/maxfreq.c
> @@ -108,6 +108,7 @@ static int maxfreq_test1(fwts_framework *fw)
>
>   	if (cpufreqs_read == 0) {
>   		fwts_skipped(fw, "Cannot read CPU frequencies from %s, this generally happens on AMD CPUs, skipping test.", CPU_INFO_PATH);
> +		free(cpufreq);
>   		return FWTS_SKIP;
>   	}
>
> @@ -116,6 +117,7 @@ static int maxfreq_test1(fwts_framework *fw)
>   			"CPUFreqNoPath",
>   			"No %s directory available: cannot test.",
>   			CPU_FREQ_PATH);
> +		free(cpufreq);
>   		return FWTS_ERROR;
>   	}
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 10, 2013, 8:55 a.m.
On 05/07/2013 06:23 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997350, Resource leak.
>
> Need to free cpufreq before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/maxfreq/maxfreq.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
> index b6fa38c..e8e6ffa 100644
> --- a/src/cpu/maxfreq/maxfreq.c
> +++ b/src/cpu/maxfreq/maxfreq.c
> @@ -108,6 +108,7 @@ static int maxfreq_test1(fwts_framework *fw)
>
>   	if (cpufreqs_read == 0) {
>   		fwts_skipped(fw, "Cannot read CPU frequencies from %s, this generally happens on AMD CPUs, skipping test.", CPU_INFO_PATH);
> +		free(cpufreq);
>   		return FWTS_SKIP;
>   	}
>
> @@ -116,6 +117,7 @@ static int maxfreq_test1(fwts_framework *fw)
>   			"CPUFreqNoPath",
>   			"No %s directory available: cannot test.",
>   			CPU_FREQ_PATH);
> +		free(cpufreq);
>   		return FWTS_ERROR;
>   	}
>
>

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

Patch

diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
index b6fa38c..e8e6ffa 100644
--- a/src/cpu/maxfreq/maxfreq.c
+++ b/src/cpu/maxfreq/maxfreq.c
@@ -108,6 +108,7 @@  static int maxfreq_test1(fwts_framework *fw)
 
 	if (cpufreqs_read == 0) {
 		fwts_skipped(fw, "Cannot read CPU frequencies from %s, this generally happens on AMD CPUs, skipping test.", CPU_INFO_PATH);
+		free(cpufreq);
 		return FWTS_SKIP;
 	}
 
@@ -116,6 +117,7 @@  static int maxfreq_test1(fwts_framework *fw)
 			"CPUFreqNoPath",
 			"No %s directory available: cannot test.",
 			CPU_FREQ_PATH);
+		free(cpufreq);
 		return FWTS_ERROR;
 	}