mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
nodedev: fix pci express memory leak
Leak introduced in commit 16ebf10f
(v1.2.6), detected by valgrind:
==9816== 216 (96 direct, 120 indirect) bytes in 6 blocks are definitely lost in loss record 665 of 821
==9816== at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9816== by 0x50836FB: virAlloc (viralloc.c:144)
==9816== by 0x1DBDBE27: udevProcessPCI (node_device_udev.c:546)
==9816== by 0x1DBDD79D: udevGetDeviceDetails (node_device_udev.c:1293)
* src/util/virpci.h (virPCIEDeviceInfoFree): New prototype.
* src/util/virpci.c (virPCIEDeviceInfoFree): New function.
* src/conf/node_device_conf.c (virNodeDevCapsDefFree): Clear
pci_express under pci case.
(virNodeDevCapPCIDevParseXML): Avoid leak.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
* src/libvirt_private.syms (virpci.h): Export it.
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
be05c1414d
commit
c6a4d268af
@ -1291,7 +1291,7 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
VIR_FREE(pci_express);
|
||||
virPCIEDeviceInfoFree(pci_express);
|
||||
ctxt->node = orignode;
|
||||
return ret;
|
||||
}
|
||||
@ -1664,6 +1664,7 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
|
||||
VIR_FREE(data->pci_dev.iommuGroupDevices[i]);
|
||||
}
|
||||
VIR_FREE(data->pci_dev.iommuGroupDevices);
|
||||
virPCIEDeviceInfoFree(data->pci_dev.pci_express);
|
||||
break;
|
||||
case VIR_NODE_DEV_CAP_USB_DEV:
|
||||
VIR_FREE(data->usb_dev.product_name);
|
||||
|
@ -1753,6 +1753,7 @@ virPCIDeviceSetUnbindFromStub;
|
||||
virPCIDeviceSetUsedBy;
|
||||
virPCIDeviceUnbind;
|
||||
virPCIDeviceWaitForCleanup;
|
||||
virPCIEDeviceInfoFree;
|
||||
virPCIGetNetName;
|
||||
virPCIGetPhysicalFunction;
|
||||
virPCIGetVirtualFunctionIndex;
|
||||
|
@ -570,7 +570,7 @@ static int udevProcessPCI(struct udev_device *device,
|
||||
|
||||
out:
|
||||
virPCIDeviceFree(pciDev);
|
||||
VIR_FREE(pci_express);
|
||||
virPCIEDeviceInfoFree(pci_express);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -2847,3 +2847,15 @@ virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev,
|
||||
virPCIDeviceConfigClose(dev, fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev)
|
||||
{
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
VIR_FREE(dev->link_cap);
|
||||
VIR_FREE(dev->link_sta);
|
||||
VIR_FREE(dev);
|
||||
}
|
||||
|
@ -212,4 +212,7 @@ int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev,
|
||||
unsigned int *cap_width,
|
||||
unsigned int *sta_speed,
|
||||
unsigned int *sta_width);
|
||||
|
||||
void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev);
|
||||
|
||||
#endif /* __VIR_PCI_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user