From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4139EC433B4 for ; Wed, 14 Apr 2021 10:07:06 +0000 (UTC) Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by mail.kernel.org (Postfix) with ESMTP id BC088613B1 for ; Wed, 14 Apr 2021 10:07:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC088613B1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org 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 Content-Transfer-Encoding: 8bit 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 --- 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