From patchwork Wed Apr 14 10:07:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 91440 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6B331A0562; Wed, 14 Apr 2021 12:07:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ED08F161923; Wed, 14 Apr 2021 12:07:04 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id B0EFF16188A for ; Wed, 14 Apr 2021 12:07:03 +0200 (CEST) IronPort-SDR: 9BSw4ZKskTuk/MQfuLe02gIcktqbXmQOK2JZHaG3UezGZs1AjKPbfgUfwmcoIRlNqlMZgjdiOD Kot3CYKIDcGg== X-IronPort-AV: E=McAfee;i="6200,9189,9953"; a="279920086" X-IronPort-AV: E=Sophos;i="5.82,221,1613462400"; d="scan'208";a="279920086" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 03:07:02 -0700 IronPort-SDR: zU2TgasIVuKSEYJPhvntUXeqWob44Db0ToGdbVWsZudhgqvMwM4IJXoZ74YHJIWFttMJtwosCY 83GEsx7BWeug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,221,1613462400"; d="scan'208";a="399131229" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.223.188]) by orsmga002.jf.intel.com with ESMTP; 14 Apr 2021 03:07:01 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: david.hunt@intel.com, reshma.pattan@intel.com Date: Wed, 14 Apr 2021 10:07:00 +0000 Message-Id: <20210414100700.127129-1-anatoly.burakov@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210413122208.101057-1-anatoly.burakov@intel.com> References: <20210413122208.101057-1-anatoly.burakov@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] power: fix resource leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-By: Reshma Pattan --- 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';