[PATCH 3/7] util: virFileIsSharedFixFUSE: Refactor cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Automatically free memory of 'canonPath' so that the failure of
'setmntent' doesn't have to go to 'cleanup'. This allows us to remove
the cleanup section and the 'ret' variable as the rest of the function
can't fail.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virfile.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 1def05b6c4..a8443acf8d 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3333,24 +3333,19 @@ virFileIsSharedFixFUSE(const char *path,
     char mntbuf[1024];
     char *mntDir = NULL;
     char *mntType = NULL;
-    char *canonPath = NULL;
+    g_autofree char *canonPath = NULL;
     size_t maxMatching = 0;
-    int ret = -1;

     if (!(canonPath = virFileCanonicalizePath(path))) {
-        virReportSystemError(errno,
-                             _("unable to canonicalize %s"),
-                             path);
+        virReportSystemError(errno, _("unable to canonicalize %s"), path);
         return -1;
     }

     VIR_DEBUG("Path canonicalization: %s->%s", path, canonPath);

     if (!(f = setmntent(PROC_MOUNTS, "r"))) {
-        virReportSystemError(errno,
-                             _("Unable to open %s"),
-                             PROC_MOUNTS);
-        goto cleanup;
+        virReportSystemError(errno, _("Unable to open %s"), PROC_MOUNTS);
+        return -1;
     }

     while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
@@ -3372,6 +3367,8 @@ virFileIsSharedFixFUSE(const char *path,
         }
     }

+    endmntent(f);
+
     if (STREQ_NULLABLE(mntType, "fuse.glusterfs")) {
         VIR_DEBUG("Found gluster FUSE mountpoint=%s for path=%s. "
                   "Fixing shared FS type", mntDir, canonPath);
@@ -3382,13 +3379,9 @@ virFileIsSharedFixFUSE(const char *path,
         *f_type = QB_MAGIC;
     }

-    ret = 0;
- cleanup:
-    VIR_FREE(canonPath);
     VIR_FREE(mntType);
     VIR_FREE(mntDir);
-    endmntent(f);
-    return ret;
+    return 0;
 }


-- 
2.37.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux