power: fix closing frequency file
authorAnatoly Burakov <anatoly.burakov@intel.com>
Wed, 14 Apr 2021 10:07:00 +0000 (10:07 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 15 Apr 2021 21:53:39 +0000 (23:53 +0200)
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")

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Reshma Pattan <reshma.pattan@intel.com>
lib/librte_power/power_pstate_cpufreq.c

index ec74515..2cfc54a 100644 (file)
@@ -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';