]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: netdevveth: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Sat, 28 Jul 2018 18:01:35 +0000 (23:31 +0530)
committerErik Skultety <eskultet@redhat.com>
Tue, 7 Aug 2018 14:29:55 +0000 (16:29 +0200)
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>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virnetdevveth.c

index 6905168120445a8cc0d6712a21a1ffb6c63acb3c..87d9d7c0cf96f012c500e2b5d862a88db8658abf 100644 (file)
@@ -46,12 +46,12 @@ 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 +111,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 +123,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 +174,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 +185,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
  cleanup:
     virMutexUnlock(&virNetDevVethCreateMutex);
     virCommandFree(cmd);
-    VIR_FREE(veth1auto);
-    VIR_FREE(veth2auto);
     return ret;
 }