[libvirt-glib 1/3] Add proper error reporting to GVirStorageVol getters

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

 



gvir_storage_vol_get_name and gvir_storage_vol_get_path currently
call g_error when an error occurs. Since g_error trigger a coredump,
calling it in a library is harmful. Replace this with proper GError
error reporting.
---
 libvirt-gobject/libvirt-gobject-storage-pool.c |   10 +++++++---
 libvirt-gobject/libvirt-gobject-storage-vol.c  |   14 ++++++++++----
 libvirt-gobject/libvirt-gobject-storage-vol.h  |    4 ++--
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index 4eb8eec..13a7f59 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -529,6 +529,7 @@ GVirStorageVol *gvir_storage_pool_create_volume
     const gchar *xml;
     virStorageVolPtr handle;
     GVirStoragePoolPrivate *priv = pool->priv;
+    const char *name;
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
@@ -546,11 +547,14 @@ GVirStorageVol *gvir_storage_pool_create_volume
     volume = GVIR_STORAGE_VOL(g_object_new(GVIR_TYPE_STORAGE_VOL,
                                            "handle", handle,
                                            NULL));
+    name = gvir_storage_vol_get_name(volume, err);
+    if (name == NULL) {
+        g_object_unref(G_OBJECT(volume));
+        return NULL;
+    }
 
     g_mutex_lock(priv->lock);
-    g_hash_table_insert(priv->volumes,
-                        g_strdup(gvir_storage_vol_get_name(volume)),
-                        volume);
+    g_hash_table_insert(priv->volumes, g_strdup(name), volume);
     g_mutex_unlock(priv->lock);
 
     return g_object_ref(volume);
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 4f62732..08ef17d 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -174,25 +174,31 @@ gvir_storage_vol_info_free(GVirStorageVolInfo *info)
 G_DEFINE_BOXED_TYPE(GVirStorageVolInfo, gvir_storage_vol_info,
                     gvir_storage_vol_info_copy, gvir_storage_vol_info_free)
 
-const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol)
+const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol, GError **error)
 {
     GVirStorageVolPrivate *priv = vol->priv;
     const char *name;
 
     if (!(name = virStorageVolGetName(priv->handle))) {
-        g_error("Failed to get storage_vol name on %p", priv->handle);
+        gvir_set_error(error, GVIR_STORAGE_VOL_ERROR, 0,
+                       "Failed to get storage_vol name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
 }
 
-const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol)
+const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol, GError **error)
 {
     GVirStorageVolPrivate *priv = vol->priv;
     const char *path;
 
     if (!(path = virStorageVolGetPath(priv->handle))) {
-        g_error("Failed to get storage_vol path on %p", priv->handle);
+        gvir_set_error(error, GVIR_STORAGE_VOL_ERROR, 0,
+                       "Failed to get storage_vol path on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return path;
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h
index db63865..fd2be80 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.h
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
@@ -77,8 +77,8 @@ GType gvir_storage_vol_get_type(void);
 GType gvir_storage_vol_info_get_type(void);
 GType gvir_storage_vol_handle_get_type(void);
 
-const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol);
-const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
+const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol, GError **error);
+const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol, GError **error);
 
 gboolean gvir_storage_vol_delete(GVirStorageVol *vol,
                                  guint flags,
-- 
1.7.7.5

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