[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 22/35] util: netdevopenvswitch: use VIR_AUTOFREE instead of VIR_FREE for scalar types



By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr gmail com>
---
 src/util/virnetdevopenvswitch.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index d1c5cf4..eff6b0f 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -149,10 +149,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
     char macaddrstr[VIR_MAC_STRING_BUFLEN];
     char ifuuidstr[VIR_UUID_STRING_BUFLEN];
     char vmuuidstr[VIR_UUID_STRING_BUFLEN];
-    char *attachedmac_ex_id = NULL;
-    char *ifaceid_ex_id = NULL;
-    char *profile_ex_id = NULL;
-    char *vmid_ex_id = NULL;
+    VIR_AUTOFREE(char *) attachedmac_ex_id = NULL;
+    VIR_AUTOFREE(char *) ifaceid_ex_id = NULL;
+    VIR_AUTOFREE(char *) profile_ex_id = NULL;
+    VIR_AUTOFREE(char *) vmid_ex_id = NULL;
 
     virMacAddrFormat(macaddr, macaddrstr);
     virUUIDFormat(ovsport->interfaceID, ifuuidstr);
@@ -209,10 +209,6 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
 
     ret = 0;
  cleanup:
-    VIR_FREE(attachedmac_ex_id);
-    VIR_FREE(ifaceid_ex_id);
-    VIR_FREE(vmid_ex_id);
-    VIR_FREE(profile_ex_id);
     virCommandFree(cmd);
     return ret;
 }
@@ -339,10 +335,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
                                    virDomainInterfaceStatsPtr stats)
 {
     virCommandPtr cmd = NULL;
-    char *output;
     char *tmp;
     bool gotStats = false;
     int ret = -1;
+    VIR_AUTOFREE(char *) output = NULL;
 
     /* Just ensure the interface exists in ovs */
     cmd = virCommandNew(OVSVSCTL);
@@ -399,7 +395,6 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
     ret = 0;
 
  cleanup:
-    VIR_FREE(output);
     virCommandFree(cmd);
     return ret;
 }
@@ -481,7 +476,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
     size_t ntokens = 0;
     int status;
     int ret = -1;
-    char *ovs_timeout = NULL;
+    VIR_AUTOFREE(char *) ovs_timeout = NULL;
 
     /* Openvswitch vhostuser path are hardcoded to
      * /<runstatedir>/openvswitch/<ifname>
@@ -513,7 +508,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
  cleanup:
     virStringListFreeCount(tokens, ntokens);
     virCommandFree(cmd);
-    VIR_FREE(ovs_timeout);
     return ret;
 }
 
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]