From nobody Mon Sep 29 22:42:47 2025 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 DE552C00140 for ; Mon, 15 Aug 2022 23:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244910AbiHOXMx (ORCPT ); Mon, 15 Aug 2022 19:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242188AbiHOXLh (ORCPT ); Mon, 15 Aug 2022 19:11:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D31DF2C; Mon, 15 Aug 2022 13:00:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 259DAB8113E; Mon, 15 Aug 2022 20:00:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A181C433C1; Mon, 15 Aug 2022 20:00:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593624; bh=OH96su+aiaQi23wTafGmmD8O4Crw/idqAWFIg1eYYPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHxBVvd6uZbIwagBtRpumBlyP7jFqrNen2hGJc15wk2fMfJ2FKwrcjkJSL6Usk82a yW/eRcKRfpJ6m2xf/4LWJEXCUBjTWH0fd7JG7ny+Cxx6lfMEciABM+qDU8BrMYM8gC C3m6pRQ37/53ERhxCukCWzXhtnGba+o11CdBxrLo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Chen Yu , Tom Rix , Len Brown , Sasha Levin Subject: [PATCH 5.19 0298/1157] tools/power turbostat: Fix file pointer leak Date: Mon, 15 Aug 2022 19:54:14 +0200 Message-Id: <20220815180451.559713255@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Colin Ian King [ Upstream commit 5e5fd36c58d6c820f7292ee492c3731c9a104a41 ] 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 [res= ourceLeak] Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count= print") Signed-off-by: Colin Ian King Acked-by: Chen Yu Reviewed-by: Tom Rix Signed-off-by: Len Brown Signed-off-by: Sasha Levin --- 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/turbos= tat/turbostat.c index ede31a4287a0..2e9a751af260 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 *c= nt) if (!fp) return -1; ret =3D fscanf(fp, "%lld", &tmp); + fclose(fp); if (ret !=3D 1) return -1; - fclose(fp); *cnt =3D tmp; =20 return 0; --=20 2.35.1