]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: netdevveth: use VIR_AUTOPTR for aggregate types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Sat, 28 Jul 2018 18:01:36 +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_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@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virnetdevveth.c

index 87d9d7c0cf96f012c500e2b5d862a88db8658abf..a651bb5445b7c704369e67f836b20b3cb19cc54a 100644 (file)
@@ -112,7 +112,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
 {
     int ret = -1;
     int vethNum = 0;
-    virCommandPtr cmd = NULL;
     size_t i;
 
     /*
@@ -125,6 +124,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
     for (i = 0; i < MAX_VETH_RETRIES; i++) {
         VIR_AUTOFREE(char *) veth1auto = NULL;
         VIR_AUTOFREE(char *) veth2auto = NULL;
+        VIR_AUTOPTR(virCommand) cmd = NULL;
 
         int status;
         if (!*veth1) {
@@ -174,8 +174,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
                   *veth1 ? *veth1 : veth1auto,
                   *veth2 ? *veth2 : veth2auto,
                   status);
-        virCommandFree(cmd);
-        cmd = NULL;
     }
 
     virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -184,7 +182,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
 
  cleanup:
     virMutexUnlock(&virNetDevVethCreateMutex);
-    virCommandFree(cmd);
     return ret;
 }
 
@@ -201,26 +198,22 @@ int virNetDevVethCreate(char** veth1, char** veth2)
  */
 int virNetDevVethDelete(const char *veth)
 {
-    virCommandPtr cmd = virCommandNewArgList("ip", "link", "del", veth, NULL);
     int status;
-    int ret = -1;
+    VIR_AUTOPTR(virCommand) cmd = virCommandNewArgList("ip", "link",
+                                                       "del", veth, NULL);
 
     if (virCommandRun(cmd, &status) < 0)
-        goto cleanup;
+        return -1;
 
     if (status != 0) {
         if (!virNetDevExists(veth)) {
             VIR_DEBUG("Device %s already deleted (by kernel namespace cleanup)", veth);
-            ret = 0;
-            goto cleanup;
+            return 0;
         }
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to delete veth device %s"), veth);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    virCommandFree(cmd);
-    return ret;
+    return 0;
 }