]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: fcp: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Fri, 13 Jul 2018 17:55:06 +0000 (23:25 +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_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/virfcp.c

index 7660ba7205067241cda534c80f6f62588417d614..b70374444ff19d87570cc34b7754773cbd9391db 100644 (file)
 bool
 virFCIsCapableRport(const char *rport)
 {
-    bool ret = false;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
 
     if (virBuildPath(&path, SYSFS_FC_RPORT_PATH, rport) < 0)
         return false;
 
-    ret = virFileExists(path);
-    VIR_FREE(path);
-
-    return ret;
+    return virFileExists(path);
 }
 
 int
@@ -57,8 +53,8 @@ virFCReadRportValue(const char *rport,
                     const char *entry,
                     char **result)
 {
-    int ret = -1;
-    char *buf = NULL, *p = NULL;
+    VIR_AUTOFREE(char *) buf = NULL;
+    char *p = NULL;
 
     if (virFileReadValueString(&buf, "%s/%s/%s",
                                SYSFS_FC_RPORT_PATH, rport, entry) < 0) {
@@ -69,13 +65,9 @@ virFCReadRportValue(const char *rport,
         *p = '\0';
 
     if (VIR_STRDUP(*result, buf) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    VIR_FREE(buf);
-    return ret;
+    return 0;
 }
 
 #else