Fix typos of function name in commit msg.
v1 version: 
https://www.redhat.com/archives/libvir-list/2018-October/msg00511.html

virFileIsSharedFixFUSE doesn't fix f_type when "fuse.glusterfs"
is not the last row of mount table. For example, it doesn't works on
the mount table like following:
10.XX.XX.XX:/gv0 /mnt fuse.glusterfs rw 0 0
r...@xx.xx.xx:/tmp/mkdir /tmp/br0 fuse.sshfs rw 0 0

Copy mnt_dir of struct mntent in case its mnt_dir is changed by
getmntent_r in the loop later.

Signed-off-by: Han Han <h...@redhat.com>
---
 src/util/virfile.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 2a7e87102a..c503462633 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3469,7 +3469,7 @@ virFileIsSharedFixFUSE(const char *path,
                        long *f_type)
 {
     char *dirpath = NULL;
-    const char **mounts = NULL;
+    char **mounts = NULL;
     size_t nmounts = 0;
     char *p;
     FILE *f = NULL;
@@ -3491,8 +3491,12 @@ virFileIsSharedFixFUSE(const char *path,
         if (STRNEQ("fuse.glusterfs", mb.mnt_type))
             continue;
 
-        if (VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mb.mnt_dir) < 0)
+        char *mnt_dir;
+        if (VIR_STRDUP(mnt_dir, mb.mnt_dir) < 0 ||
+                VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mnt_dir) < 0) {
+            VIR_FREE(mnt_dir);
             goto cleanup;
+        }
     }
 
     /* Add NULL sentinel so that this is a virStringList */
@@ -3512,7 +3516,7 @@ virFileIsSharedFixFUSE(const char *path,
         else
             *p = '\0';
 
-        if (virStringListHasString(mounts, dirpath)) {
+        if (virStringListHasString((const char **)mounts, dirpath)) {
             VIR_DEBUG("Found gluster FUSE mountpoint=%s for path=%s. "
                       "Fixing shared FS type", dirpath, path);
             *f_type = GFS2_MAGIC;
@@ -3523,7 +3527,7 @@ virFileIsSharedFixFUSE(const char *path,
     ret = 0;
  cleanup:
     endmntent(f);
-    VIR_FREE(mounts);
+    virStringListFree(mounts);
     VIR_FREE(dirpath);
     return ret;
 }
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to