[PATCH 1/2] rbd: Only close RBD image if it has been opened

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

 



It could be that we error out while the RBD image has not been
opened yet. This would cause us to call rbd_close() on pointer
which has not been initialized.

Set it to NULL by default and only close if it is not NULL.

Signed-off-by: Wido den Hollander <wido@xxxxxxxxx>
---
 src/storage/storage_backend_rbd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 80684eb..8e2d51b 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -281,13 +281,13 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
 {
     int ret = -1;
     int r = 0;
-    rbd_image_t image;
+    rbd_image_t image = NULL;
 
     r = rbd_open(ptr->ioctx, vol->name, &image, NULL);
     if (r < 0) {
         virReportSystemError(-r, _("failed to open the RBD image '%s'"),
                              vol->name);
-        return ret;
+        goto cleanup;
     }
 
     rbd_image_info_t info;
@@ -323,7 +323,8 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
     ret = 0;
 
  cleanup:
-    rbd_close(image);
+    if (image)
+        rbd_close(image);
     return ret;
 }
 
-- 
1.9.1

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



[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]