power: fix crash on error for intel_pstate
authorAnatoly Burakov <anatoly.burakov@intel.com>
Fri, 9 Jul 2021 15:55:59 +0000 (15:55 +0000)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 20 Jul 2021 15:24:00 +0000 (17:24 +0200)
Currently, the error paths can lead to attempts at dereferencing NULL
pointers. Add the check to avoid attempts at dereferencing NULL
pointers.

Coverity issue: 371895
Coverity issue: 371889
Fixes: 06cffd468fdd ("power: refactor ACPI and intel_pstate support")

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
lib/power/power_pstate_cpufreq.c

index ba28ddc..3b60751 100644 (file)
@@ -440,8 +440,10 @@ power_get_available_freqs(struct pstate_power_info *pi)
                        num_freqs, pi->lcore_id);
 
 out:
-       fclose(f_min);
-       fclose(f_max);
+       if (f_min != NULL)
+               fclose(f_min);
+       if (f_max != NULL)
+               fclose(f_max);
 
        return ret;
 }