From nobody Sun Nov 24 17:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1722424776; cv=none; d=zohomail.com; s=zohoarc; b=Q1YIAL17Tlus4HW+Xm5VTjNiwmddTYb9XgvWiw92vtFqgzFmv9rEVDHHYCviFUNV23qu2KCpRi+/Nj525F9L+X5YH2mXWEz7Fehpt3wvheI6jhuL6j2sayTAB4fdLgJXjmV+aRtxS4dB7ZkxAw3T7pIqfsqPfwFOL3f2T0dsrr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722424776; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=18y0TLtURaACI8V2aaTdx66LDye0ViTKACpdUCycGOc=; b=Dg82wrL72IWmi7zyiTYJB4Awo1D+O60VaxDwpH54DfEFG4kClOPfNKAFWPMoptYxYUFH3p6K6lS90q4yuf7ZQjAI/rcSZoFkJarpZaj47nVWFiOPxZ9p3eqMwrthoFQgMmqmcb6f+a/WM9BUCrAQSf6u+vKjM16jWurDHl631n8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172242477656624.952134543747093; Wed, 31 Jul 2024 04:19:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZ7Lq-0005vk-Ty; Wed, 31 Jul 2024 07:18:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZ7Lo-0005qU-Q8 for qemu-devel@nongnu.org; Wed, 31 Jul 2024 07:18:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZ7Lm-0006n0-Jd for qemu-devel@nongnu.org; Wed, 31 Jul 2024 07:18:36 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-mZP7SxbPNEe1Dib0YLDEdA-1; Wed, 31 Jul 2024 07:18:32 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a7d2f42df2dso112414866b.1 for ; Wed, 31 Jul 2024 04:18:32 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb9a12sm753487266b.213.2024.07.31.04.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 04:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722424714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=18y0TLtURaACI8V2aaTdx66LDye0ViTKACpdUCycGOc=; b=MWZoVF8MdPGpmVoW8Wn9/uDMXVOF1K/IAjxEw6A7SHzWGRZhbHe9uwT18yBASJcExJpxpN IekJvWH0yPpN6A1cabhEvvJWpq2MuLq5CJhAbDSnek/lEOCFtqhQGpOIjH0kCsZyKFilsM bH8j1TofYkxQCv5SSIMgeUR8Sj2/8Mc= X-MC-Unique: mZP7SxbPNEe1Dib0YLDEdA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722424711; x=1723029511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=18y0TLtURaACI8V2aaTdx66LDye0ViTKACpdUCycGOc=; b=b5Jr5BQUvuKhIi22yqDengmRDEgJ/nc67LXhACCXOWyCfrVvReLOeIKBUn5teyG5aW D4Ubk4J1AKyLSImTyCTtgkWH4im8tvbcEqcMGUgtGY/rNFqHSQdl95c1wIlZuNbGQOQ3 /n/nKBdsKza6elEzSWvPxEQyx9BzYL21C2ec5qqBSStZspBxp8soUnFYeKfVnuioo1at GQ+xSTS+83qFSNCjb2RsbF8FBanL8hoks74yPPuVH6eb0XMyiu4IcWkbxE4DxmzkOIPO phclIP1RuHMnDL4vrbgilJJc+ULeYCAtDkWdNgYQ5hf0d7881t7Y9X0coDrCRpbOoSo9 a+gA== X-Gm-Message-State: AOJu0Yx+WOXXAxKxZJiYZ2MXADuhJYPJ0hITYpoEvl61Eo2oeHi6nIRA Zv9dgIWcISc4QuFulqra8Al+dMBVvnkuou3PpvvvldM/akth/bejOKMpbDRHQX0NimcFanvwIRJ P2tCzSvnI8uCNYZf41NduKgiflXd9azS+vVtVgPt8UffrSs3q8Je2NGIk22DxralEuFIPfinqT0 Gc/kiNkjpESXpbzBai5ZLJgurP8CtC8dWN0bTX X-Received: by 2002:a17:906:ee88:b0:a72:7b17:5d68 with SMTP id a640c23a62f3a-a7d858bb113mr453611066b.3.1722424710969; Wed, 31 Jul 2024 04:18:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFrpNWcr2QiySQj46ryyYBfW4GM0BDhjlW41oxX5veSGug3PpZi9xTYcCb6m1pC3vXggA/FA== X-Received: by 2002:a17:906:ee88:b0:a72:7b17:5d68 with SMTP id a640c23a62f3a-a7d858bb113mr453609066b.3.1722424710518; Wed, 31 Jul 2024 04:18:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Anthony Harivel Subject: [PULL 08/10] target/i386: Clean up error cases for vmsr_read_thread_stat() Date: Wed, 31 Jul 2024 13:18:04 +0200 Message-ID: <20240731111806.167225-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731111806.167225-1-pbonzini@redhat.com> References: <20240731111806.167225-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.126, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1722424778750116600 Content-Type: text/plain; charset="utf-8" From: Anthony Harivel Fix leaking memory of file handle in case of error Erase unused "pid =3D -1" Add clearer error_report Should fix Coverity CID 1558557. Signed-off-by: Anthony Harivel Link: https://lore.kernel.org/r/20240726102632.1324432-3-aharivel@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/kvm/vmsr_energy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/vmsr_energy.c b/target/i386/kvm/vmsr_energy.c index a1d78f2f2ae..7e064c5aef3 100644 --- a/target/i386/kvm/vmsr_energy.c +++ b/target/i386/kvm/vmsr_energy.c @@ -270,7 +270,7 @@ void vmsr_read_thread_stat(pid_t pid, =20 FILE *file =3D fopen(path, "r"); if (file =3D=3D NULL) { - pid =3D -1; + error_report("Error opening %s", path_name); return; } =20 @@ -279,7 +279,8 @@ void vmsr_read_thread_stat(pid_t pid, " %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %*u %*u %u", utime, stime, cpu_id) !=3D 3) { - pid =3D -1; + fclose(file); + error_report("Error fscanf did not report the right amount of item= s"); return; } =20 --=20 2.45.2