Use g_autofree in strings when possible to spare a VIR_FREE()
call. Unneeded 'cleanup' labels will be taken care of in the
next patch.

The 'str' string in virDomainVirtioSerialAddrReserve() was
never used by the logic, only being used in cleanup by
VIR_FREE(). Let's remove it.

Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com>
---
 src/conf/domain_addr.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index ef7ee80e6a..ee4dcf1d3b 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -830,7 +830,7 @@ 
virDomainPCIAddressReserveAddrInternal(virDomainPCIAddressSetPtr addrs,
                                        bool fromConfig)
 {
     int ret = -1;
-    char *addrStr = NULL;
+    g_autofree char *addrStr = NULL;
     virDomainPCIAddressBusPtr bus;
     virErrorNumber errType = (fromConfig
                               ? VIR_ERR_XML_ERROR : VIR_ERR_INTERNAL_ERROR);
@@ -891,7 +891,6 @@ 
virDomainPCIAddressReserveAddrInternal(virDomainPCIAddressSetPtr addrs,
 
     ret = 0;
  cleanup:
-    VIR_FREE(addrStr);
     return ret;
 }
 
@@ -912,7 +911,7 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr 
addrs,
                               virDomainPCIConnectFlags flags)
 {
     int ret = -1;
-    char *addrStr = NULL;
+    g_autofree char *addrStr = NULL;
 
     /* if flags is 0, the particular model of this device on this
      * machinetype doesn't need a PCI address, so we're done.
@@ -955,7 +954,6 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr 
addrs,
     ret = 0;
 
  cleanup:
-    VIR_FREE(addrStr);
     return ret;
 }
 
@@ -1105,7 +1103,7 @@ 
virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus,
                                            bool *found)
 {
     int ret = -1;
-    char *addrStr = NULL;
+    g_autofree char *addrStr = NULL;
 
     *found = false;
 
@@ -1159,7 +1157,6 @@ 
virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus,
     ret = 0;
 
  cleanup:
-    VIR_FREE(addrStr);
     return ret;
 }
 
@@ -1414,7 +1411,7 @@ virDomainCCWAddressAssign(virDomainDeviceInfoPtr dev,
                           bool autoassign)
 {
     int ret = -1;
-    char *addr = NULL;
+    g_autofree char *addr = NULL;
 
     if (dev->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW)
         return 0;
@@ -1457,7 +1454,6 @@ virDomainCCWAddressAssign(virDomainDeviceInfoPtr dev,
     ret = 0;
 
  cleanup:
-    VIR_FREE(addr);
     return ret;
 }
 
@@ -1687,7 +1683,6 @@ virDomainVirtioSerialAddrReserve(virDomainDefPtr def 
G_GNUC_UNUSED,
                                  void *data)
 {
     virDomainVirtioSerialAddrSetPtr addrs = data;
-    char *str = NULL;
     int ret = -1;
     virBitmapPtr map = NULL;
     bool b;
@@ -1729,7 +1724,6 @@ virDomainVirtioSerialAddrReserve(virDomainDefPtr def 
G_GNUC_UNUSED,
     ret = 0;
 
  cleanup:
-    VIR_FREE(str);
     return ret;
 }
 
@@ -2208,7 +2202,7 @@ virDomainUSBAddressSetAddHub(virDomainUSBAddressSetPtr 
addrs,
     virDomainUSBAddressHubPtr targetHub = NULL, newHub = NULL;
     int ret = -1;
     int targetPort;
-    char *portStr = NULL;
+    g_autofree char *portStr = NULL;
 
     if (hub->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -2242,7 +2236,6 @@ virDomainUSBAddressSetAddHub(virDomainUSBAddressSetPtr 
addrs,
     ret = 0;
  cleanup:
     virDomainUSBAddressHubFree(newHub);
-    VIR_FREE(portStr);
     return ret;
 }
 
@@ -2349,7 +2342,7 @@ 
virDomainUSBAddressAssignFromBus(virDomainUSBAddressSetPtr addrs,
 {
     unsigned int portpath[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH] = { 0 };
     virDomainUSBAddressHubPtr hub = addrs->buses[bus];
-    char *portStr = NULL;
+    g_autofree char *portStr = NULL;
     int ret = -1;
 
     if (!hub)
@@ -2372,7 +2365,6 @@ 
virDomainUSBAddressAssignFromBus(virDomainUSBAddressSetPtr addrs,
 
     ret = 0;
  cleanup:
-    VIR_FREE(portStr);
     return ret;
 }
 
@@ -2428,7 +2420,7 @@ virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
 {
     virDomainUSBAddressSetPtr addrs = data;
     virDomainUSBAddressHubPtr targetHub = NULL;
-    char *portStr = NULL;
+    g_autofree char *portStr = NULL;
     int ret = -1;
     int targetPort;
 
@@ -2459,7 +2451,6 @@ virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
     ret = 0;
 
  cleanup:
-    VIR_FREE(portStr);
     return ret;
 }
 
@@ -2490,7 +2481,7 @@ virDomainUSBAddressRelease(virDomainUSBAddressSetPtr 
addrs,
                            virDomainDeviceInfoPtr info)
 {
     virDomainUSBAddressHubPtr targetHub = NULL;
-    char *portStr = NULL;
+    g_autofree char *portStr = NULL;
     int targetPort;
     int ret = -1;
 
@@ -2510,6 +2501,5 @@ virDomainUSBAddressRelease(virDomainUSBAddressSetPtr 
addrs,
     ret = 0;
 
  cleanup:
-    VIR_FREE(portStr);
     return ret;
 }
-- 
2.24.1


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

Reply via email to