]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: file: use VIR_AUTOPTR for aggregate types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Fri, 13 Jul 2018 17:54:49 +0000 (23:24 +0530)
committerErik Skultety <eskultet@redhat.com>
Sat, 14 Jul 2018 15:01:30 +0000 (17:01 +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/virfile.c

index 3a7445f039e2f912622f4b1f64c487c16af6fc90..6b94885a872a993ed50fd48b7cd1249aaebf05b8 100644 (file)
@@ -888,20 +888,19 @@ int virFileNBDDeviceAssociate(const char *file,
 {
     VIR_AUTOFREE(char *) nbddev = NULL;
     VIR_AUTOFREE(char *) qemunbd = NULL;
-    virCommandPtr cmd = NULL;
-    int ret = -1;
+    VIR_AUTOPTR(virCommand) cmd = NULL;
     const char *fmtstr = NULL;
 
     if (!virFileNBDLoadDriver())
-        goto cleanup;
+        return -1;
 
     if (!(nbddev = virFileNBDDeviceFindUnused()))
-        goto cleanup;
+        return -1;
 
     if (!(qemunbd = virFindFileInPath("qemu-nbd"))) {
         virReportSystemError(ENOENT, "%s",
                              _("Unable to find 'qemu-nbd' binary in $PATH"));
-        goto cleanup;
+        return -1;
     }
 
     if (fmt > 0)
@@ -926,17 +925,14 @@ int virFileNBDDeviceAssociate(const char *file,
     /* qemu-nbd will daemonize itself */
 
     if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     VIR_DEBUG("Associated NBD device %s with file %s and format %s",
               nbddev, file, fmtstr);
     *dev = nbddev;
     nbddev = NULL;
-    ret = 0;
 
- cleanup:
-    virCommandFree(cmd);
-    return ret;
+    return 0;
 }
 
 #else /* __linux__ */