power: fix resource leak
PATCH 1/1 power: fix resource leak
Currently, we open the system base frequency file, but never close it, which results in a memory leak.
Coverity issue: 369693
---
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.
lib/librte_power/power_pstate_cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)
lib/librte_power/power_pstate_cpufreq.c +3 -0
@@ -185,6 +185,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi) base_max_ratio =strtoul (buf_base,NULL ,POWER_CONVERT_TO_DECIMAL ) /BUS_FREQ ; +/* not needed any more */ +fclose (f_base_max); + f_base_max =NULL ; } snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,
Signature · 1 line
2.25.1
lib/librte_power/power_pstate_cpufreq.c power_init_for_setting_freq(struct pstate_power_info *pi) · line 190
Quoted 11 lines
-----Original Message-----
From: Burakov, Anatoly <[email protected]>(quoted diff) +0
-0base_max_ratio = strtoul(buf_base, NULL,
POWER_CONVERT_TO_DECIMAL)lib/librte_power/power_pstate_cpufreq.c +3
-0/ BUS_FREQ; +/* not needed any more */ +fclose (f_base_max); + f_base_max =NULL ;
Should this be moved before FOPS_OR_NULL_GOTO() call ?
Quoted 14 lines · Reshma
lib/librte_power/power_pstate_cpufreq.c power_init_for_setting_freq(struct pstate_power_info *pi) · line 190
Quoted 11 lines
-----Original Message-----
From: Burakov, Anatoly <[email protected]>
base_max_ratio=
strtoul(buf_base, NULL,POWER_CONVERT_TO_DECIMAL)
/BUS_FREQ;lib/librte_power/power_pstate_cpufreq.c +3
-0+/* not needed any more */ +fclose (f_base_max); +f_base_max =NULL ;Should this be moved before
FOPS_OR_NULL_GOTO()call ?
No, otherwise we wouldn't be able to read the data. It *could* be moved to the end, but then we'd have to modify the rest of the logic as well, because right after this there are unconditional returns there. All of this is addressed in a refactor patch [1], this is just fixing a bug and nothing else.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
Signature · 2 lines
Thanks, Anatoly
Quoted 16 lines · Anatoly
Quoted 14 lines · Reshma
lib/librte_power/power_pstate_cpufreq.c power_init_for_setting_freq(struct pstate_power_info *pi) · line 190
Quoted 11 lines
-----Original Message-----
From: Burakov, Anatoly <[email protected]>base_max_ratio=
strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL)
/BUS_FREQ;lib/librte_power/power_pstate_cpufreq.c +3
-0+/* not needed any more */ +fclose (f_base_max); +f_base_max =NULL ;Should this be moved before
FOPS_OR_NULL_GOTO()call ?
Quoted 5 lines
No, otherwise we wouldn't be able to read the data. It *could* be moved to the end, but then we'd have to modify the rest of the logic as well, because right after this there are unconditional returns there. All of this is addressed in a refactor patch [1], this is just fixing a bug and nothing else.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
Actually, no, you're right! This does have to be moved till before FOPS_OR_NULL_GOTO, because this is where we actually read the data (if we fail to read data, we leak). I hate this code :D
Signature · 2 lines
Thanks, Anatoly
PATCH v2 1/1 power: fix resource leak
In reply to Anatoly BurakovCurrently, we open the system base frequency file, but never close it, which results in a memory leak.
Coverity issue: 369693
---
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(+)
lib/librte_power/power_pstate_cpufreq.c +5 -0
@@ -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' ;
Signature · 1 line
2.25.1
Quoted 10 lines
-----Original Message-----
From: Burakov, Anatoly <[email protected]> Coverity issue: 369693Fixes 8a5febaac4f7 ("power: fix P-state base frequency handling")v2:
- Move the fd close to before we check read data
Thomas Monjalon
AppliedQuoted 6 lines
Quoted 4 lines
From: Burakov, Anatoly <[email protected]> Coverity issue: 369693
Fixes 8a5febaac4f7 ("power: fix P-state base frequency handling")Acked-by Reshma Pattan <[email protected]>
Applied, thanks