File 64d32118-fix-nodedev-memleak.patch of Package libvirt.33033

commit 64d32118540aca3d42bc5ee21c8b780cafe04bfa
Author: Michal Prívozník <mprivozn@redhat.com>
Date:   Wed Nov 30 14:53:21 2022 +0100

    node_device_conf: Avoid memleak in virNodeDeviceGetPCIVPDDynamicCap()
    
    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=2143235
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
    Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Index: libvirt-8.0.0/src/conf/node_device_conf.c
===================================================================
--- libvirt-8.0.0.orig/src/conf/node_device_conf.c
+++ libvirt-8.0.0/src/conf/node_device_conf.c
@@ -3019,6 +3019,9 @@ virNodeDeviceGetPCIVPDDynamicCap(virNode
     virPCIDeviceAddress devAddr;
     g_autoptr(virPCIVPDResource) res = NULL;
 
+    g_clear_pointer(&devCapPCIDev->vpd, virPCIVPDResourceFree);
+    devCapPCIDev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_VPD;
+
     devAddr.domain = devCapPCIDev->domain;
     devAddr.bus = devCapPCIDev->bus;
     devAddr.slot = devCapPCIDev->slot;
@@ -3032,8 +3035,6 @@ virNodeDeviceGetPCIVPDDynamicCap(virNode
         if ((res = virPCIDeviceGetVPD(pciDev))) {
             devCapPCIDev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VPD;
             devCapPCIDev->vpd = g_steal_pointer(&res);
-        } else {
-            virPCIVPDResourceFree(g_steal_pointer(&devCapPCIDev->vpd));
         }
     }
     return 0;
openSUSE Build Service is sponsored by