Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3028017rwb; Mon, 15 Aug 2022 16:26:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6HeoA/r5xbAcKHMGFiD++8gF7EFX/azhDaSz6DymfTwYhGVJAJg4WF953p3yEIKc4sLvkP X-Received: by 2002:a17:906:84ef:b0:730:ba33:512b with SMTP id zp15-20020a17090684ef00b00730ba33512bmr11831871ejb.346.1660605986085; Mon, 15 Aug 2022 16:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605986; cv=none; d=google.com; s=arc-20160816; b=eckzH2JUOOxlArp/4bbLU1NZPYm1VfDgG2SQv5hOMyeggUYYlkNHTvepPAcOSxvqL0 9/D9f/NgfX4XJfL+8W8hZkWM+s0/+2tYWR5YiuS7O9qqJ6apFyJffuZMJ3WYLrH+ELzy tS4UMJFOCkYxVZIHCz+8Hck4RiYkmiKodkmLSwQTY8Uk+i+W4ivVzhc6G+ilw3WY1evI h47snYDU0WYrfhZoDIAmrTZQIvehcD/qCcoohNnY0c498tpJRdjokzf1QzS49d4XossE Uk1cyhPDfH8iJYh/t4lreeCOMGGSTbZ5rWc5bgDdhZ9L0xrF+cZz3o/jbJltmzZkBRW0 LQZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cAo30taqlQ7ojD6XOG6IlCT3m4UZxbzjp+nqSL5l5Hg=; b=fnRsn+Hf4YEXXL/IM4vs2e35APzSlLGHLwUnz99xoEgZ6qbDw2yWt1tmWgPx5KYLx5 UKHW0/Y0UwcoC1MQDxxydsPap7aTWnSTk6esAP5nE0Ux3obyB+peMPtYrpWt7IJLLwxE 5WbuIkJuez6dCuGaI2R3LA7lxSjFNowj/p7thxvQw6cJD5dHq9K7BDVeuYbzacZxoQG6 VpBwudpdElbrQWXmKKtGmkMWXuLHREQ36ip/GxVQgjwIXiFKIeSIszLJZN3PB+NTFbWb R6QeFoupd5jOLG5VVnu8STkuYbE8phJyDADb+YWnWBjAne2b7r07J46JBdQH6UEpNAqE ivAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CHxBVvd6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj2-20020a1709069c8200b0072fa2e742f4si1207428ejc.906.2022.08.15.16.26.00; Mon, 15 Aug 2022 16:26:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CHxBVvd6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245445AbiHOXMw (ORCPT + 99 others); Mon, 15 Aug 2022 19:12:52 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 [resourceLeak] 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/turbostat/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 *cnt) if (!fp) return -1; ret = fscanf(fp, "%lld", &tmp); + fclose(fp); if (ret != 1) return -1; - fclose(fp); *cnt = tmp; return 0; -- 2.35.1