From: Michal Privoznik <mprivozn(a)redhat.com>
For an USB device, the virt-aa-helper must put that
/dev/bus/usb/... path associated with given device. The way the
code is currently written not only leads to a memleak (the @usb
variable is allocated only to be overwritten right away), but is
needlessly cumbersome.
We can use virHostdevFindUSBDevice() to find the USB device,
check if its missing and if not add the path associated with it
into the profile.
While at it, also use automatic memory freeing for the variable.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/security/virt-aa-helper.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index d4358ebf9c..a56d7e9062 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1040,24 +1040,21 @@ get_files(vahControl * ctl)
for (i = 0; i < ctl->def->nhostdevs; i++)
if (ctl->def->hostdevs[i]) {
virDomainHostdevDef *dev = ctl->def->hostdevs[i];
- virDomainHostdevSubsysUSB *usbsrc = &dev->source.subsys.u.usb;
if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
- virUSBDevice *usb =
- virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL);
-
- if (usb == NULL)
- continue;
+ g_autoptr(virUSBDevice) usb = NULL;
if (virHostdevFindUSBDevice(dev, true, &usb) < 0)
continue;
+ if (dev->missing)
+ continue;
+
rc = virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf);
- virUSBDeviceFree(usb);
if (rc != 0)
goto cleanup;
break;
--
2.49.0