From nobody Tue May 21 04:47:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669824491; cv=none; d=zohomail.com; s=zohoarc; b=CEmon8hZbPTf3rvxCFYCtDEruX6w/wK8sqnv2qR/lQ12N94eddcN7BQqwx3wWsAXIyZ8PFNrZj06HHCxSO8WomkdEuDRBv2cmuJb2Lvvc1SkDYaZ9SIvO8PRaNG3K4F40KdRFckY+d9mChpaNE9ZVjejhoKGH1uK4e48Vldp8SY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669824491; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=JeNQhmSgHXtaRW24fCMeDjs/mDNL0rRyka7L3Fx3K20=; b=m1FIwYOCog/P94gHEWg5MibNRUTEJwiQYHy73GHyHSp5vefczhkQ5vMpsRE3hZA+H9l3x8cWWnERN1UzJm0Sx1iohdgQnlAHOjMAxUumDdOvRL8zCnksypE9yLV+LW43BdpTqcGweGoypcEFmina1IwuQtpw8eRZWyTvpVlZglI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1669824491575328.32334719076243; Wed, 30 Nov 2022 08:08:11 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-175-mq2aIOS0PTqL-rQV7TIDug-1; Wed, 30 Nov 2022 11:07:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 801F8101CC62; Wed, 30 Nov 2022 16:07:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68CA940C9563; Wed, 30 Nov 2022 16:07:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AD36419465A4; Wed, 30 Nov 2022 16:07:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4F7F61946586 for ; Wed, 30 Nov 2022 15:25:09 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2FF012166B2D; Wed, 30 Nov 2022 15:25:09 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.40.23.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id C69362166B26 for ; Wed, 30 Nov 2022 15:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669824490; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JeNQhmSgHXtaRW24fCMeDjs/mDNL0rRyka7L3Fx3K20=; b=C3EyLjTITImWTJYP6wy6IPOebY7kvg5HbN3SQziVbrtZgCD4COJWUNfMcNylIRp3Cd52yS CgaHUaaHyZv+6CHb8tpEUhkGFNMdSWPSy/a73t/tDGySdDhR4XQUunXRwwV3jD0e1GA/UN BReUpwgkV0Lpa8c2HrfHDiE1VuVKqkA= X-MC-Unique: mq2aIOS0PTqL-rQV7TIDug-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] node_device_conf: Avoid memleak in virNodeDeviceGetPCIVPDDynamicCap() Date: Wed, 30 Nov 2022 16:25:05 +0100 Message-Id: <512b8043c28eb88ac62cf6edec74827d35315a1d.1669821905.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669824492007100002 Content-Type: text/plain; charset="utf-8"; x-default="true" The virNodeDeviceGetPCIVPDDynamicCap() function is called from virNodeDeviceGetPCIDynamicCaps() and therefore has to be a wee bit more clever about adding VPD capability. Namely, it has to remove the old one before adding a new one. This is how other functions called from virNodeDeviceGetPCIDynamicCaps() behave as well. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2143235 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/node_device_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 83e66b85e3..af331baaf3 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -3068,6 +3068,9 @@ virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev = *devCapPCIDev) virPCIDeviceAddress devAddr =3D { 0 }; g_autoptr(virPCIVPDResource) res =3D NULL; =20 + g_clear_pointer(&devCapPCIDev->vpd, virPCIVPDResourceFree); + devCapPCIDev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_VPD; + devAddr.domain =3D devCapPCIDev->domain; devAddr.bus =3D devCapPCIDev->bus; devAddr.slot =3D devCapPCIDev->slot; @@ -3081,8 +3084,6 @@ virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev = *devCapPCIDev) if ((res =3D virPCIDeviceGetVPD(pciDev))) { devCapPCIDev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VPD; devCapPCIDev->vpd =3D g_steal_pointer(&res); - } else { - virPCIVPDResourceFree(g_steal_pointer(&devCapPCIDev->vpd)); } } return 0; --=20 2.37.4