power: fix file descriptor leak
authorLiang Ma <liang.j.ma@intel.com>
Tue, 15 Jan 2019 10:01:37 +0000 (10:01 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 17 Jan 2019 18:20:02 +0000 (19:20 +0100)
Coverity issue: 328528
Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility")

Signed-off-by: Liang Ma <liang.j.ma@intel.com>
Reviewed-by: Lei Yao <lei.a.yao@intel.com>
Tested-by: Lei Yao <lei.a.yao@intel.com>
Signed-off-by: David Hunt <david.hunt@intel.com>
lib/librte_power/power_pstate_cpufreq.c

index c4d972f..9c1a162 100644 (file)
@@ -160,6 +160,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
                        pi->lcore_id);
 
        f_max = fopen(fullpath_max, "rw+");
+       if (f_max == NULL)
+               fclose(f_min);
+
        FOPEN_OR_ERR_RET(f_max, -1);
 
        pi->f_cur_min = f_min;
@@ -398,6 +401,9 @@ power_get_available_freqs(struct pstate_power_info *pi)
        FOPEN_OR_ERR_RET(f_min, ret);
 
        f_max = fopen(fullpath_max, "r");
+       if (f_max == NULL)
+               fclose(f_min);
+
        FOPEN_OR_ERR_RET(f_max, ret);
 
        s_min = fgets(buf_min, sizeof(buf_min), f_min);