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 <skrtbht...@gmail.com>
Reviewed-by: Erik Skultety <eskul...@redhat.com>
---
 src/util/virnetdevveth.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 6905168..8c1a7f3 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -46,12 +46,11 @@ virMutex virNetDevVethCreateMutex = VIR_MUTEX_INITIALIZER;
 static int virNetDevVethExists(int devNum)
 {
     int ret;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0)
         return -1;
     ret = virFileExists(path) ? 1 : 0;
     VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret);
-    VIR_FREE(path);
     return ret;
 }
 
@@ -111,8 +110,6 @@ static int virNetDevVethGetFreeNum(int startDev)
 int virNetDevVethCreate(char** veth1, char** veth2)
 {
     int ret = -1;
-    char *veth1auto = NULL;
-    char *veth2auto = NULL;
     int vethNum = 0;
     virCommandPtr cmd = NULL;
     size_t i;
@@ -125,6 +122,9 @@ int virNetDevVethCreate(char** veth1, char** veth2)
 #define MAX_VETH_RETRIES 10
 
     for (i = 0; i < MAX_VETH_RETRIES; i++) {
+        VIR_AUTOFREE(char *) veth1auto = NULL;
+        VIR_AUTOFREE(char *) veth2auto = NULL;
+
         int status;
         if (!*veth1) {
             int veth1num;
@@ -173,8 +173,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
                   *veth1 ? *veth1 : veth1auto,
                   *veth2 ? *veth2 : veth2auto,
                   status);
-        VIR_FREE(veth1auto);
-        VIR_FREE(veth2auto);
         virCommandFree(cmd);
         cmd = NULL;
     }
@@ -186,8 +184,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
  cleanup:
     virMutexUnlock(&virNetDevVethCreateMutex);
     virCommandFree(cmd);
-    VIR_FREE(veth1auto);
-    VIR_FREE(veth2auto);
     return ret;
 }
 
-- 
1.8.3.1

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

Reply via email to