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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95FB5C433EF for ; Tue, 26 Apr 2022 13:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346119AbiDZNmm (ORCPT ); Tue, 26 Apr 2022 09:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239468AbiDZNml (ORCPT ); Tue, 26 Apr 2022 09:42:41 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A2A66AE6; Tue, 26 Apr 2022 06:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650980374; x=1682516374; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=7fuoHjFYh58bCMLDeH91TfTPQ3w0G2M79t/dH46cWVM=; b=kk55sE6m9ngH5zhZlN111jJef38ZLzfv5FlpLa3wXk/eaTmdeWxfHChL xQUTRX38IL78SDBiIZ9xIZ3QXUhSV6LL7I9IkNWmqPdt1J0wGRaKCrPaY Uh9aBFJEIpotgaWJcKgG0bRBd55X2qcPpX8ijPagbESMlI/uXpF3B7huC dpExB89eB1unPmgwo0xbk4vZYlCad05KFFgACmT6PJoHcExEVN/IUmiF/ xGei0lYlG/hP2fxwmZquqiS9JqtTBmDxAc3jQLT/Y/U1PLJNIdX61PyBA XrCZfxxP5tEc1jkYH23m9hjGJnyCYiZyt0bGbnySP0IcME9mDXYriRThK w==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="252955802" X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="252955802" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 06:39:33 -0700 X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="579898754" Received: from dongyiyu-mobl1.ccr.corp.intel.com (HELO chenyu5-mobl1) ([10.249.173.93]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 06:39:30 -0700 Date: Tue, 26 Apr 2022 21:39:26 +0800 From: Chen Yu To: Colin Ian King Cc: Len Brown , linux-pm@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/power turbostat: Fix file pointer leak Message-ID: <20220426133926.GA33188@chenyu5-mobl1> References: <20220426131607.1520483-1-colin.i.king@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426131607.1520483-1-colin.i.king@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On Tue, Apr 26, 2022 at 02:16:07PM +0100, Colin Ian King wrote: > Currently if a fscanf fails then an early return leaks an open > file pointer. Fix this by fclosing the file before the return. > Detected using static analysis with cppcheck: > > tools/power/x86/turbostat/turbostat.c:2039:3: error: Resource leak: fp [resourceLeak] > > Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print") > Signed-off-by: Colin Ian King > --- > tools/power/x86/turbostat/turbostat.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c > index e6779f599a8e..db431b31c4df 100644 > --- a/tools/power/x86/turbostat/turbostat.c > +++ b/tools/power/x86/turbostat/turbostat.c > @@ -2035,9 +2035,9 @@ int get_core_throt_cnt(int cpu, unsigned long long *cnt) > if (!fp) > return -1; > ret = fscanf(fp, "%lld", &tmp); > + fclose(fp); > if (ret != 1) > return -1; > - fclose(fp); > *cnt = tmp; > > return 0; Acked-by: Chen Yu Thanks for fixing it. Chenyu