libs/power: fix the resource leaking issue

Message ID 20190115100137.47470-1-david.hunt@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series libs/power: fix the resource leaking issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Hunt, David Jan. 15, 2019, 10:01 a.m. UTC
  From: Liang Ma <liang.j.ma@intel.com>

Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility")
Coverity issue: 328528

v2: focus just on the resource leak. Remove additional code around
    Turbo Boost frequency handling.

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 | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Thomas Monjalon Jan. 17, 2019, 5:26 p.m. UTC | #1
15/01/2019 11:01, David Hunt:
> From: Liang Ma <liang.j.ma@intel.com>
> 
> Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility")
> Coverity issue: 328528
> 
> v2: focus just on the resource leak. Remove additional code around
>     Turbo Boost frequency handling.
> 
> 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>
> ---
> --- a/lib/librte_power/power_pstate_cpufreq.c
> +++ b/lib/librte_power/power_pstate_cpufreq.c
>  	f_max = fopen(fullpath_max, "rw+");
> +
> +	if (f_max == NULL)
> +		fclose(f_min);

No need to insert a blank line before "if". Removing on apply.

Applied, thanks
  

Patch

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index c4d972fc0..079822bf7 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -160,6 +160,10 @@  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 +402,10 @@  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);