From: Michal Privoznik Date: Mon, 2 Feb 2026 14:54:15 +0000 (+0100) Subject: bhyve: Avoid leaking @addrs in bhyveDomainAssignPCIAddresses() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ce8c35c29a0d8061d662195eacfb592c831f6dc;p=thirdparty%2Flibvirt.git bhyve: Avoid leaking @addrs in bhyveDomainAssignPCIAddresses() 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 lost 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 Reviewed-by: Roman Bogorodskiy --- 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 = NULL; bhyveDomainObjPrivate *priv = NULL; + int ret = -1; if (!(addrs = bhyveDomainPCIAddressSetCreate(def, 1))) return -1; if (bhyveAssignDevicePCISlots(def, addrs) < 0) - return -1; + goto cleanup; if (obj && obj->privateData) { priv = obj->privateData; if (addrs) { virDomainPCIAddressSetFree(priv->pciaddrs); priv->persistentAddrs = 1; - priv->pciaddrs = addrs; + priv->pciaddrs = g_steal_pointer(&addrs); } else { priv->persistentAddrs = 0; } } - return 0; + ret = 0; + cleanup: + virDomainPCIAddressSetFree(addrs); + return ret; } int bhyveDomainAssignAddresses(virDomainDef *def, virDomainObj *obj)