From: Yi Li Date: Thu, 31 Oct 2019 03:55:26 +0000 (+0800) Subject: storage: improve the while loop virStorageBackendFileSystemIsMounted X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=94af82b936a7064a68133058090a799af078143d;p=libvirt.git storage: improve the while loop virStorageBackendFileSystemIsMounted Move virStorageBackendFileSystemGetPoolSource outside of the while loop Signed-off-by: Yi Li Signed-off-by: Ján Tomko Reviewed-by: Ján Tomko --- diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 02b824867a..27c10982e4 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 */ @@ -273,8 +273,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) ret = 1; goto cleanup; } - - VIR_FREE(src); } ret = 0;