Re: [libvirt] [PATCH v2 10/39] qemuDomainGetHostdevPath: Use more VIR_AUTOFREE/VIR_AUTOPTR

2019-10-17 Thread Cole Robinson
On 9/26/19 12:12 PM, Michal Privoznik wrote:
> There are several variables which could be automatically freed
> upon return from the function. I'm not changing @tmpPaths (which
> is a string list) because it is going to be removed in next
> commit.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  src/qemu/qemu_domain.c | 18 ++
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 

With the appropriate GLib adjustments:

Reviewed-by: Cole Robinson 

I see you've already made adjustments in your branch. If a v3 is coming
then I endorse pushing some of these cleanup pieces out of band, just to
reduce the patch count.

- Cole

> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index c903750fa0..d8d2f72bcc 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -12866,14 +12866,14 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>  virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
>  virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
> >source.subsys.u.scsi_host;
>  virDomainHostdevSubsysMediatedDevPtr mdevsrc = 
> >source.subsys.u.mdev;
> -virPCIDevicePtr pci = NULL;
> -virUSBDevicePtr usb = NULL;
> -virSCSIDevicePtr scsi = NULL;
> -virSCSIVHostDevicePtr host = NULL;
> -char *tmpPath = NULL;
> +VIR_AUTOPTR(virPCIDevice) pci = NULL;
> +VIR_AUTOPTR(virUSBDevice) usb = NULL;
> +VIR_AUTOPTR(virSCSIDevice) scsi = NULL;
> +VIR_AUTOPTR(virSCSIVHostDevice) host = NULL;
> +VIR_AUTOFREE(char *) tmpPath = NULL;
>  bool includeVFIO = false;
>  char **tmpPaths = NULL;
> -int *tmpPerms = NULL;
> +VIR_AUTOFREE(int *) tmpPerms = NULL;
>  size_t tmpNpaths = 0;
>  int perm = 0;
>  
> @@ -13004,12 +13004,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>  ret = 0;
>   cleanup:
>  virStringListFreeCount(tmpPaths, tmpNpaths);
> -VIR_FREE(tmpPerms);
> -virPCIDeviceFree(pci);
> -virUSBDeviceFree(usb);
> -virSCSIDeviceFree(scsi);
> -virSCSIVHostDeviceFree(host);
> -VIR_FREE(tmpPath);
>  return ret;
>  }
>  
> 


- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 10/39] qemuDomainGetHostdevPath: Use more VIR_AUTOFREE/VIR_AUTOPTR

2019-09-26 Thread Michal Privoznik
There are several variables which could be automatically freed
upon return from the function. I'm not changing @tmpPaths (which
is a string list) because it is going to be removed in next
commit.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_domain.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c903750fa0..d8d2f72bcc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -12866,14 +12866,14 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
 virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
-virPCIDevicePtr pci = NULL;
-virUSBDevicePtr usb = NULL;
-virSCSIDevicePtr scsi = NULL;
-virSCSIVHostDevicePtr host = NULL;
-char *tmpPath = NULL;
+VIR_AUTOPTR(virPCIDevice) pci = NULL;
+VIR_AUTOPTR(virUSBDevice) usb = NULL;
+VIR_AUTOPTR(virSCSIDevice) scsi = NULL;
+VIR_AUTOPTR(virSCSIVHostDevice) host = NULL;
+VIR_AUTOFREE(char *) tmpPath = NULL;
 bool includeVFIO = false;
 char **tmpPaths = NULL;
-int *tmpPerms = NULL;
+VIR_AUTOFREE(int *) tmpPerms = NULL;
 size_t tmpNpaths = 0;
 int perm = 0;
 
@@ -13004,12 +13004,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 ret = 0;
  cleanup:
 virStringListFreeCount(tmpPaths, tmpNpaths);
-VIR_FREE(tmpPerms);
-virPCIDeviceFree(pci);
-virUSBDeviceFree(usb);
-virSCSIDeviceFree(scsi);
-virSCSIVHostDeviceFree(host);
-VIR_FREE(tmpPath);
 return ret;
 }
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list