[libvirt] [PATCH v2] storage: improve the while loop virStorageBackendFileSystemIsMounted

Yi Li posted 1 patch 4 years, 5 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1572495900-31014-1-git-send-email-yili@winhong.com
src/storage/storage_backend_fs.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[libvirt] [PATCH v2] storage: improve the while loop virStorageBackendFileSystemIsMounted
Posted by Yi Li 4 years, 5 months ago
Move virStorageBackendFileSystemGetPoolSource outside of the while loop

Signed-off-by: Yi Li <yili@winhong.com>
---
 src/storage/storage_backend_fs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 02b8248..92516c8 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -258,10 +258,10 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
         goto cleanup;
     }
 
-    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
-        if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
-            goto cleanup;
+    if ((src = virStorageBackendFileSystemGetPoolSource(pool)) == NULL)
+        goto cleanup;
 
+    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
         /* compare both mount destinations and sources to be sure the mounted
          * FS pool is really the one we're looking for
          */
@@ -274,12 +274,13 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
             goto cleanup;
         }
 
-        VIR_FREE(src);
     }
 
     ret = 0;
 
  cleanup:
+    if (src)
+        VIR_FREE(src);
     VIR_FORCE_FCLOSE(mtab);
     return ret;
 }
-- 
2.7.5



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