On Sat, Jul 21, 2018 at 05:36:53PM +0530, Sukrit Bhatnagar wrote: > By making use of GNU C's cleanup attribute handled by the > VIR_AUTOPTR macro for declaring aggregate pointer variables, > majority of the calls to *Free functions can be dropped, which > in turn leads to getting rid of most of our cleanup sections. > > Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx> > --- > src/util/virpci.c | 51 ++++++++++++++++++--------------------------------- > 1 file changed, 18 insertions(+), 33 deletions(-) > > diff --git a/src/util/virpci.c b/src/util/virpci.c > index 1f6ac0b..7b0964c 100644 > --- a/src/util/virpci.c > +++ b/src/util/virpci.c > @@ -490,8 +490,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate, > ret = 1; > break; > } > - > - virPCIDeviceFree(check); > } > VIR_DIR_CLOSE(dir); > return ret; ... > @@ -1679,19 +1675,16 @@ virPCIGetAddrString(unsigned int domain, > unsigned int function, > char **pciConfigAddr) > { > - virPCIDevicePtr dev = NULL; > - int ret = -1; > + VIR_AUTOPTR(virPCIDevice) dev = NULL; > > dev = virPCIDeviceNew(domain, bus, slot, function); > if (dev != NULL) { > if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0) > - goto cleanup; > - ret = 0; > + return -1; > + return 0; if (!dev || VIR_STRDUP(*pciConfigAddr, dev->name) < 0)) return -1; > } > > - cleanup: > - virPCIDeviceFree(dev); > - return ret; > + return -1; ^return 0; > } > > virPCIDevicePtr > @@ -1962,10 +1955,10 @@ virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev) > > if (!copy) > return -1; > - if (virPCIDeviceListAdd(list, copy) < 0) { > - virPCIDeviceFree(copy); > + if (virPCIDeviceListAdd(list, copy) < 0) > return -1; > - } > + > + copy = NULL; You'll first need to define copy as VIR_AUTOPTR, if you want to use ^this assignment, otherwise it's a NOP. There may be some leftovers from the previous patch that will need to go into this one, otherwise looks fine. Erik -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list