DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] power: fix resource leak
@ 2021-04-13 12:22 Anatoly Burakov
  2021-04-14  9:24 ` Pattan, Reshma
  2021-04-14 10:07 ` [dpdk-dev] [PATCH v2] " Anatoly Burakov
  0 siblings, 2 replies; 7+ messages in thread
From: Anatoly Burakov @ 2021-04-13 12:22 UTC (permalink / raw)
  To: dev; +Cc: david.hunt, reshma.pattan

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.

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

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index ec745153d3..1451a024be 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -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,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] power: fix resource leak
  2021-04-13 12:22 [dpdk-dev] [PATCH] power: fix resource leak Anatoly Burakov
@ 2021-04-14  9:24 ` Pattan, Reshma
  2021-04-14 10:00   ` Burakov, Anatoly
  2021-04-14 10:07 ` [dpdk-dev] [PATCH v2] " Anatoly Burakov
  1 sibling, 1 reply; 7+ messages in thread
From: Pattan, Reshma @ 2021-04-14  9:24 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: Hunt, David



> -----Original Message-----
> From: Burakov, Anatoly <anatoly.burakov@intel.com>
>  		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;

Should this be moved before FOPS_OR_NULL_GOTO() call ?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] power: fix resource leak
  2021-04-14  9:24 ` Pattan, Reshma
@ 2021-04-14 10:00   ` Burakov, Anatoly
  2021-04-14 10:02     ` Burakov, Anatoly
  0 siblings, 1 reply; 7+ messages in thread
From: Burakov, Anatoly @ 2021-04-14 10:00 UTC (permalink / raw)
  To: Pattan, Reshma, dev; +Cc: Hunt, David

On 14-Apr-21 10:24 AM, Pattan, Reshma wrote:
> 
> 
>> -----Original Message-----
>> From: Burakov, Anatoly <anatoly.burakov@intel.com>
>>   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;
> 
> 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/20210402092701.258316-1-anatoly.burakov@intel.com/

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] power: fix resource leak
  2021-04-14 10:00   ` Burakov, Anatoly
@ 2021-04-14 10:02     ` Burakov, Anatoly
  0 siblings, 0 replies; 7+ messages in thread
From: Burakov, Anatoly @ 2021-04-14 10:02 UTC (permalink / raw)
  To: Pattan, Reshma, dev; +Cc: Hunt, David

On 14-Apr-21 11:00 AM, Burakov, Anatoly wrote:
> On 14-Apr-21 10:24 AM, Pattan, Reshma wrote:
>>
>>
>>> -----Original Message-----
>>> From: Burakov, Anatoly <anatoly.burakov@intel.com>
>>>   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;
>>
>> 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/20210402092701.258316-1-anatoly.burakov@intel.com/ 
> 
> 

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

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [dpdk-dev] [PATCH v2] power: fix resource leak
  2021-04-13 12:22 [dpdk-dev] [PATCH] power: fix resource leak Anatoly Burakov
  2021-04-14  9:24 ` Pattan, Reshma
@ 2021-04-14 10:07 ` Anatoly Burakov
  2021-04-14 10:16   ` Pattan, Reshma
  1 sibling, 1 reply; 7+ messages in thread
From: Anatoly Burakov @ 2021-04-14 10:07 UTC (permalink / raw)
  To: dev; +Cc: david.hunt, reshma.pattan

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(+)

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';
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH v2] power: fix resource leak
  2021-04-14 10:07 ` [dpdk-dev] [PATCH v2] " Anatoly Burakov
@ 2021-04-14 10:16   ` Pattan, Reshma
  2021-04-15 21:55     ` Thomas Monjalon
  0 siblings, 1 reply; 7+ messages in thread
From: Pattan, Reshma @ 2021-04-14 10:16 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: Hunt, David



> -----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>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH v2] power: fix resource leak
  2021-04-14 10:16   ` Pattan, Reshma
@ 2021-04-15 21:55     ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2021-04-15 21:55 UTC (permalink / raw)
  To: Burakov, Anatoly; +Cc: dev, Hunt, David, Pattan, Reshma

> > 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-15 21:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 12:22 [dpdk-dev] [PATCH] power: fix resource leak Anatoly Burakov
2021-04-14  9:24 ` Pattan, Reshma
2021-04-14 10:00   ` Burakov, Anatoly
2021-04-14 10:02     ` Burakov, Anatoly
2021-04-14 10:07 ` [dpdk-dev] [PATCH v2] " Anatoly Burakov
2021-04-14 10:16   ` Pattan, Reshma
2021-04-15 21:55     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).