From nobody Mon Feb 9 02:51:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1770133360; cv=none; d=zohomail.com; s=zohoarc; b=XjpTiy2xdbNf19hJS2AmO9IyN7VjPTu2miSt/480PCKTwRMV6QBY+A6oiD6wnO2oa69CJtAlHcE5OnWcXv9pxvXF5B68BL+F0hLNMUuSeYZVNbXR9dQqgCpfUI3dQL0I7AVVLvtCgc4GHOYeIc2bOaOJQ3oy3e48QoiznL6glRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770133360; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=Wf8UiCEfV+UWMs8xNMpJukhLQVGa32G5ip41FFwh1rg=; b=C6tHDNIg1JztH1xjC5zFI7GzFWQ5K0tOkMlULguA+J9ZZyutPWYht+FK9zwkvup7/o5ileEoMlFBHQZoInV5Tz//TOF8gKBKrjr0HN/a+Pod+HLjKyqJNEhZSGnhBIdktw97YCjoE8g8MY+GlFHnIxfF8yqms1oAC7IdgNbgEeA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1770133360340776.7652341787992; Tue, 3 Feb 2026 07:42:40 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 9327541A2C; Tue, 3 Feb 2026 10:42:39 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 92E0C43DD2; Tue, 3 Feb 2026 10:40:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 421DF41817; Tue, 3 Feb 2026 10:40:06 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BA3C641984 for ; Tue, 3 Feb 2026 10:40:05 -0500 (EST) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-cSEhlfUdOaOLDd8M_87Ctw-1; Tue, 03 Feb 2026 10:40:04 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3BD9B195422D for ; Tue, 3 Feb 2026 15:40:03 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 98D721956048 for ; Tue, 3 Feb 2026 15:40:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770133205; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=Wf8UiCEfV+UWMs8xNMpJukhLQVGa32G5ip41FFwh1rg=; b=Tj/8pWCcgo6KzKDrlB0HEK73o4+45NB2fGW7IFlHICKkVxYm5VTVPZgEN6ofbEbJClo+HV /ZvyN9AIjoPC7e57tmNlCpw2lQeoyCyNmYKr4ZIN72fqNDKXD+Iktwt3Dy5ZMh4AmWsOgQ 6wGjurE1c7PNsQTvwDb0kxaQ+nv+q9c= X-MC-Unique: cSEhlfUdOaOLDd8M_87Ctw-1 X-Mimecast-MFC-AGG-ID: cSEhlfUdOaOLDd8M_87Ctw_1770133203 To: devel@lists.libvirt.org Subject: [PATCH 2/9] bhyve: Avoid leaking @addrs in bhyveDomainAssignPCIAddresses() Date: Tue, 3 Feb 2026 16:39:50 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: M_yrC_dlOq9wnTiPhHADqUFg_cVpsWeon29ymlyi33I_1770133203 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3Y24VTXWIMKU43US5O2ORO3U2N6364L2 X-Message-ID-Hash: 3Y24VTXWIMKU43US5O2ORO3U2N6364L2 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1770133361056158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Inside of bhyveDomainAssignPCIAddresses() the @addr variable is allocated and in a few cases stolen into domain private data. But in all other cases the associated memory is never freed. 12,800 (3,200 direct, 9,600 indirect) bytes in 100 blocks are definitely lo= st in loss record 533 of 538 at 0x4888098: calloc (vg_replace_malloc.c:1682) by 0x4EE67D9: g_malloc0_n (in /usr/local/lib/libglib-2.0.so.0.8400.4) by 0x4AFD4AC: virDomainPCIAddressSetAlloc (domain_addr.c:1011) by 0x4020F68: bhyveDomainPCIAddressSetCreate (bhyve_device.c:65) by 0x40210BD: bhyveDomainAssignPCIAddresses (bhyve_device.c:219) by 0x402180C: bhyveDomainAssignAddresses (bhyve_device.c:241) by 0x4020083: bhyveDomainDefAssignAddresses (bhyve_domain.c:230) by 0x4B71820: virDomainDefPostParse (domain_postparse.c:1503) by 0x4B28282: virDomainDefParseNode (domain_conf.c:20565) by 0x4B2810B: virDomainDefParse (domain_conf.c:20502) by 0x4B281DF: virDomainDefParseFile (domain_conf.c:20549) by 0x4015D6B: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:47) Signed-off-by: Michal Privoznik --- src/bhyve/bhyve_device.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index 28a9c82d7b..54511383bb 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -215,25 +215,29 @@ int bhyveDomainAssignPCIAddresses(virDomainDef *def, { virDomainPCIAddressSet *addrs =3D NULL; bhyveDomainObjPrivate *priv =3D NULL; + int ret =3D -1; =20 if (!(addrs =3D bhyveDomainPCIAddressSetCreate(def, 1))) return -1; =20 if (bhyveAssignDevicePCISlots(def, addrs) < 0) - return -1; + goto cleanup; =20 if (obj && obj->privateData) { priv =3D obj->privateData; if (addrs) { virDomainPCIAddressSetFree(priv->pciaddrs); priv->persistentAddrs =3D 1; - priv->pciaddrs =3D addrs; + priv->pciaddrs =3D g_steal_pointer(&addrs); } else { priv->persistentAddrs =3D 0; } } =20 - return 0; + ret =3D 0; + cleanup: + virDomainPCIAddressSetFree(addrs); + return ret; } =20 int bhyveDomainAssignAddresses(virDomainDef *def, virDomainObj *obj) --=20 2.52.0