[v2] power: fix resource leak

Message ID 20210414100700.127129-1-anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] power: fix resource leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Burakov, Anatoly April 14, 2021, 10:07 a.m. UTC
  Currently, we open the system base frequency file, but never close it,
which results in a memory leak.

Coverity issue: 369693

Fixes: 8a5febaac4f7 ("power: fix P-state base frequency handling")
Cc: david.hunt@intel.com
Cc: reshma.pattan@intel.com

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    Ideally, the close should be added at the end, but there's a bunch of ERR_RET
    macros before that, so addressing that would put us dangerously close to
    refactoring, which is not what we want to do so close to the release.
    
    This issue was already "fixed", but because the variable naming and the flow of
    code is confusing, the fix was addressing a different variable. There is a
    patch for 21.08 that will address the code flow and make it less confusing.
    
    v2:
    - Move the fd close to before we check read data

 lib/librte_power/power_pstate_cpufreq.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Pattan, Reshma April 14, 2021, 10:16 a.m. UTC | #1
> -----Original Message-----
> From: Burakov, Anatoly <anatoly.burakov@intel.com>
> Coverity issue: 369693
> 
> Fixes: 8a5febaac4f7 ("power: fix P-state base frequency handling")
>     v2:
>     - Move the fd close to before we check read data
> 

Acked-By: Reshma Pattan <reshma.pattan@intel.com>
  
Thomas Monjalon April 15, 2021, 9:55 p.m. UTC | #2
> > From: Burakov, Anatoly <anatoly.burakov@intel.com>
> > Coverity issue: 369693
> > 
> > Fixes: 8a5febaac4f7 ("power: fix P-state base frequency handling")
> 
> Acked-By: Reshma Pattan <reshma.pattan@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index ec745153d3..2cfc54acf3 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -175,6 +175,11 @@  power_init_for_setting_freq(struct pstate_power_info *pi)
 	FOPEN_OR_ERR_RET(f_base_max, -1);
 	if (f_base_max != NULL) {
 		s_base_max = fgets(buf_base, sizeof(buf_base), f_base_max);
+
+		/* close the file unconditionally */
+		fclose(f_base_max);
+		f_base_max = NULL;
+
 		FOPS_OR_NULL_GOTO(s_base_max, out);
 
 		buf_base[BUFSIZ-1] = '\0';