[PATCH] cpu: cpufreq: fix leak of file if fgets returns NULL

Keng-Yu Lin kengyu at canonical.com
Thu May 9 06:35:05 UTC 2013


On Tue, May 7, 2013 at 5:30 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Coverity CID #997353, Resource leak.
>
> Need to close file before we return.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index fa10275..5133f51 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -250,8 +250,10 @@ static void do_cpu(fwts_framework *fw, int cpu)
>                 }
>                 return;
>         }
> -       if (fgets(line, 4095, file) == NULL)
> +       if (fgets(line, 4095, file) == NULL) {
> +               fclose(file);
>                 return;
> +       }
>         fclose(file);
>
>         if (total_tests == 1)
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list