]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: Avoid leaking @addrs in bhyveDomainAssignPCIAddresses()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 2 Feb 2026 14:54:15 +0000 (15:54 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Feb 2026 07:29:38 +0000 (08:29 +0100)
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 <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
src/bhyve/bhyve_device.c

index 28a9c82d7ba15a5a4423d500925ac9e60e6a8a51..54511383bb34a0330b362ac0913ab03530149858 100644 (file)
@@ -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)