[libvirt-glib] Check arguments to public libvirt-gobject methods

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

 



Some public methods in libvirt-gobject don't have g_return_if_fail
checks on their arguments. It happens that GNOME Boxes tries to call
gvir_connection_find_storage_pool_by_name with a NULL GVirConnection
causing a crash https://bugzilla.gnome.org/show_bug.cgi?id=676216 While
GNOME Boxes needs to be fixed not to pass an invalid value to this
function, it's better if libvirt-object sanity checks the argument it is
passed by the caller before using them.  In this commit, I've went over
all libvirt-gobject public functions to add g_return_if_fail checks
where needed.
---
 libvirt-gobject/libvirt-gobject-connection.c       |  122 +++++++++++++++++---
 libvirt-gobject/libvirt-gobject-domain-device.c    |    4 +
 libvirt-gobject/libvirt-gobject-domain-disk.c      |    1 +
 libvirt-gobject/libvirt-gobject-domain-interface.c |    1 +
 libvirt-gobject/libvirt-gobject-domain-snapshot.c  |    7 +-
 libvirt-gobject/libvirt-gobject-domain.c           |   70 +++++++++--
 libvirt-gobject/libvirt-gobject-interface.c        |   13 ++-
 libvirt-gobject/libvirt-gobject-manager.c          |   27 +++--
 libvirt-gobject/libvirt-gobject-network-filter.c   |   14 ++-
 libvirt-gobject/libvirt-gobject-network.c          |   13 ++-
 libvirt-gobject/libvirt-gobject-node-device.c      |   14 ++-
 libvirt-gobject/libvirt-gobject-secret.c           |    6 +-
 libvirt-gobject/libvirt-gobject-storage-pool.c     |   61 ++++++++--
 libvirt-gobject/libvirt-gobject-storage-vol.c      |   33 ++++--
 libvirt-gobject/libvirt-gobject-stream.c           |    6 +
 15 files changed, 321 insertions(+), 71 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index b12669d..3a99034 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -407,7 +407,14 @@ gboolean gvir_connection_open(GVirConnection *conn,
                               GCancellable *cancellable,
                               GError **err)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable),
+                         FALSE);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+    priv = conn->priv;
 
     if (g_cancellable_set_error_if_cancelled(cancellable, err))
         return FALSE;
@@ -486,6 +493,9 @@ void gvir_connection_open_async(GVirConnection *conn,
 {
     GSimpleAsyncResult *res;
 
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     res = g_simple_async_result_new(G_OBJECT(conn),
                                     callback,
                                     user_data,
@@ -521,8 +531,12 @@ gboolean gvir_connection_open_finish(GVirConnection *conn,
 
 gboolean gvir_connection_is_open(GVirConnection *conn)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     gboolean open = TRUE;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     if (!priv->conn)
         open = FALSE;
@@ -532,7 +546,12 @@ gboolean gvir_connection_is_open(GVirConnection *conn)
 
 void gvir_connection_close(GVirConnection *conn)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
+
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+
+    priv = conn->priv;
+
     g_debug("Close GVirConnection=%p", conn);
 
     g_mutex_lock(priv->lock);
@@ -613,7 +632,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
                                        GCancellable *cancellable,
                                        GError **err)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GHashTable *doms;
     gchar **inactive = NULL;
     gint ninactive = 0;
@@ -624,6 +643,12 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
     virConnectPtr vconn = NULL;
     GError *lerr = NULL;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable),
+                         FALSE);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR,
@@ -742,7 +767,7 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
                                              GCancellable *cancellable,
                                              GError **err)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GHashTable *pools;
     gchar **inactive = NULL;
     gint ninactive = 0;
@@ -753,6 +778,12 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
     virConnectPtr vconn = NULL;
     GError *lerr = NULL;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable),
+                         FALSE);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR,
@@ -891,6 +922,9 @@ void gvir_connection_fetch_domains_async(GVirConnection *conn,
 {
     GSimpleAsyncResult *res;
 
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     res = g_simple_async_result_new(G_OBJECT(conn),
                                     callback,
                                     user_data,
@@ -950,6 +984,9 @@ void gvir_connection_fetch_storage_pools_async(GVirConnection *conn,
 {
     GSimpleAsyncResult *res;
 
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     res = g_simple_async_result_new(G_OBJECT(conn),
                                     callback,
                                     user_data,
@@ -983,8 +1020,9 @@ gboolean gvir_connection_fetch_storage_pools_finish(GVirConnection *conn,
 
 const gchar *gvir_connection_get_uri(GVirConnection *conn)
 {
-    GVirConnectionPrivate *priv = conn->priv;
-    return priv->uri;
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+
+    return conn->priv->uri;
 }
 
 static void gvir_domain_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
@@ -1004,9 +1042,12 @@ static void gvir_domain_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
  */
 GList *gvir_connection_get_domains(GVirConnection *conn)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GList *domains = NULL;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     if (priv->domains != NULL) {
         domains = g_hash_table_get_values(priv->domains);
@@ -1030,9 +1071,12 @@ GList *gvir_connection_get_domains(GVirConnection *conn)
  */
 GList *gvir_connection_get_storage_pools(GVirConnection *conn)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GList *pools = NULL;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     if (priv->pools != NULL) {
         pools = g_hash_table_get_values(priv->pools);
@@ -1054,8 +1098,13 @@ GList *gvir_connection_get_storage_pools(GVirConnection *conn)
 GVirDomain *gvir_connection_get_domain(GVirConnection *conn,
                                        const gchar *uuid)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GVirDomain *dom;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(uuid != NULL, NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     dom = g_hash_table_lookup(priv->domains, uuid);
     if (dom)
@@ -1075,9 +1124,13 @@ GVirDomain *gvir_connection_get_domain(GVirConnection *conn,
 GVirStoragePool *gvir_connection_get_storage_pool(GVirConnection *conn,
                                                   const gchar *uuid)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GVirStoragePool *pool;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(uuid != NULL, NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     pool = g_hash_table_lookup(priv->pools, uuid);
     if (pool)
@@ -1098,10 +1151,13 @@ GVirStoragePool *gvir_connection_get_storage_pool(GVirConnection *conn,
 GVirDomain *gvir_connection_find_domain_by_id(GVirConnection *conn,
                                               gint id)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GHashTableIter iter;
     gpointer key, value;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     g_hash_table_iter_init(&iter, priv->domains);
 
@@ -1132,10 +1188,14 @@ GVirDomain *gvir_connection_find_domain_by_id(GVirConnection *conn,
 GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
                                                 const gchar *name)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GHashTableIter iter;
     gpointer key, value;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(name != NULL, NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     g_hash_table_iter_init(&iter, priv->domains);
 
@@ -1168,10 +1228,14 @@ GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
 GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn,
                                                            const gchar *name)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     GHashTableIter iter;
     gpointer key, value;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(name != NULL, NULL);
+
+    priv = conn->priv;
     g_mutex_lock(priv->lock);
     g_hash_table_iter_init(&iter, priv->pools);
 
@@ -1253,12 +1317,17 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
 {
     gchar *xml;
     virDomainPtr handle;
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(conf), NULL);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), NULL);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
     g_return_val_if_fail(xml != NULL, NULL);
 
+    priv = conn->priv;
     handle = virDomainDefineXML(priv->conn, xml);
     g_free(xml);
     if (!handle) {
@@ -1302,12 +1371,17 @@ GVirDomain *gvir_connection_start_domain(GVirConnection *conn,
 {
     gchar *xml;
     virDomainPtr handle;
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(conf), NULL);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), NULL);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
     g_return_val_if_fail(xml != NULL, NULL);
 
+    priv = conn->priv;
     handle = virDomainCreateXML(priv->conn, xml, flags);
     g_free(xml);
     if (!handle) {
@@ -1350,12 +1424,17 @@ GVirStoragePool *gvir_connection_create_storage_pool
                                  GError **err) {
     const gchar *xml;
     virStoragePoolPtr handle;
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(conf), NULL);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), NULL);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
     g_return_val_if_fail(xml != NULL, NULL);
 
+    priv = conn->priv;
     if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                flags,
@@ -1390,10 +1469,14 @@ GVirStoragePool *gvir_connection_create_storage_pool
 GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
                                             GError **err)
 {
-    GVirConnectionPrivate *priv = conn->priv;
+    GVirConnectionPrivate *priv;
     virNodeInfo info;
     GVirNodeInfo *ret;
 
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), NULL);
+
+    priv = conn->priv;
     if (virNodeGetInfo(priv->conn, &info) < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
@@ -1480,6 +1563,9 @@ void gvir_connection_get_capabilities_async(GVirConnection *conn,
 {
     GSimpleAsyncResult *res;
 
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     res = g_simple_async_result_new(G_OBJECT(conn),
                                     callback,
                                     user_data,
diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c
index 9a65468..f2f3dfc 100644
--- a/libvirt-gobject/libvirt-gobject-domain-device.c
+++ b/libvirt-gobject/libvirt-gobject-domain-device.c
@@ -167,6 +167,8 @@ virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self)
  */
 GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device)
 {
+    g_return_val_if_fail(GVIR_IS_DOMAIN_DEVICE(device), NULL);
+
     return g_object_ref (device->priv->domain);
 }
 
@@ -180,6 +182,8 @@ GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device)
  */
 GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device)
 {
+    g_return_val_if_fail(GVIR_IS_DOMAIN_DEVICE(device), NULL);
+
     return g_object_ref (device->priv->config);
 }
 
diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c b/libvirt-gobject/libvirt-gobject-domain-disk.c
index 607e26c..46b47fd 100644
--- a/libvirt-gobject/libvirt-gobject-domain-disk.c
+++ b/libvirt-gobject/libvirt-gobject-domain-disk.c
@@ -124,6 +124,7 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **e
     const gchar *path;
 
     g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL);
+    g_return_val_if_fail((err == NULL) || (*err == NULL), NULL);
 
     handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
     path = gvir_domain_disk_get_path (self);
diff --git a/libvirt-gobject/libvirt-gobject-domain-interface.c b/libvirt-gobject/libvirt-gobject-domain-interface.c
index 7087cbc..3ae9a46 100644
--- a/libvirt-gobject/libvirt-gobject-domain-interface.c
+++ b/libvirt-gobject/libvirt-gobject-domain-interface.c
@@ -126,6 +126,7 @@ GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *s
     const gchar *path;
 
     g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
 
     handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
     path = gvir_domain_interface_get_path (self);
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
index d06d4d5..11a073c 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
@@ -161,6 +161,7 @@ G_DEFINE_BOXED_TYPE(GVirDomainSnapshotHandle, gvir_domain_snapshot_handle,
 
 const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot)
 {
+    g_return_val_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
 #if 0
     GVirDomainSnapshotPrivate *priv = snapshot->priv;
     const char *name;
@@ -194,9 +195,13 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config
                                  guint flags,
                                  GError **err)
 {
-    GVirDomainSnapshotPrivate *priv = snapshot->priv;
+    GVirDomainSnapshotPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = snapshot->priv;
     if (!(xml = virDomainSnapshotGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_DOMAIN_SNAPSHOT_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 9be568a..59af63f 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -274,9 +274,12 @@ G_DEFINE_BOXED_TYPE(GVirDomainInfo, gvir_domain_info,
 
 const gchar *gvir_domain_get_name(GVirDomain *dom)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     const char *name;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
+
+    priv = dom->priv;
     if (!(name = virDomainGetName(priv->handle))) {
         g_warning("Failed to get domain name on %p", priv->handle);
         return NULL;
@@ -296,9 +299,13 @@ const gchar *gvir_domain_get_uuid(GVirDomain *dom)
 gint gvir_domain_get_id(GVirDomain *dom,
                         GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     gint ret;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), -1);
+    g_return_val_if_fail(err == NULL || *err == NULL, -1);
+
+    priv = dom->priv;
     if ((ret = virDomainGetID(priv->handle)) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -317,9 +324,13 @@ gboolean gvir_domain_start(GVirDomain *dom,
                            guint flags,
                            GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     int ret;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+    priv = dom->priv;
     if (flags)
         ret = virDomainCreateWithFlags(priv->handle, flags);
     else
@@ -344,8 +355,12 @@ gboolean gvir_domain_start(GVirDomain *dom,
 gboolean gvir_domain_resume(GVirDomain *dom,
                             GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+    priv = dom->priv;
     if (virDomainResume(priv->handle) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -365,9 +380,13 @@ gboolean gvir_domain_stop(GVirDomain *dom,
                           guint flags,
                           GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     int ret;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+    priv = dom->priv;
     if (flags)
         ret = virDomainDestroyFlags(priv->handle, flags);
     else
@@ -391,9 +410,13 @@ gboolean gvir_domain_delete(GVirDomain *dom,
                             guint flags,
                             GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     int ret;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+    priv = dom->priv;
     if (flags)
         ret = virDomainUndefineFlags(priv->handle, flags);
     else
@@ -417,8 +440,12 @@ gboolean gvir_domain_shutdown(GVirDomain *dom,
                               guint flags G_GNUC_UNUSED,
                               GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
+    priv = dom->priv;
     if (virDomainShutdown(priv->handle) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -438,8 +465,12 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
                             guint flags,
                             GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
+    priv = dom->priv;
     if (virDomainReboot(priv->handle, flags) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -462,9 +493,13 @@ GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
                                          guint flags,
                                          GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = dom->priv;
     if (!(xml = virDomainGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -501,12 +536,13 @@ gboolean gvir_domain_set_config(GVirDomain *domain,
     virConnectPtr conn;
     virDomainPtr handle;
     gchar uuid[VIR_UUID_STRING_BUFLEN];
-    GVirDomainPrivate *priv = domain->priv;
+    GVirDomainPrivate *priv;
 
     g_return_val_if_fail(GVIR_IS_DOMAIN (domain), FALSE);
     g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
     g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
+    priv = domain->priv;
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
     g_return_val_if_fail(xml != NULL, FALSE);
@@ -556,10 +592,14 @@ gboolean gvir_domain_set_config(GVirDomain *domain,
 GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
                                      GError **err)
 {
-    GVirDomainPrivate *priv = dom->priv;
+    GVirDomainPrivate *priv;
     virDomainInfo info;
     GVirDomainInfo *ret;
 
+    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = dom->priv;
     if (virDomainGetInfo(priv->handle, &info) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
                                0,
@@ -613,6 +653,7 @@ void gvir_domain_get_info_async(GVirDomain *dom,
     GSimpleAsyncResult *res;
 
     g_return_if_fail(GVIR_IS_DOMAIN(dom));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
 
     res = g_simple_async_result_new(G_OBJECT(dom),
                                     callback,
@@ -679,6 +720,7 @@ gchar *gvir_domain_screenshot(GVirDomain *dom,
 
     g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
     g_return_val_if_fail(GVIR_IS_STREAM(stream), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
 
     priv = dom->priv;
     g_object_get(stream, "handle", &st, NULL);
@@ -725,6 +767,7 @@ gboolean gvir_domain_open_console(GVirDomain *dom,
 
     g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
     g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     priv = dom->priv;
     g_object_get(stream, "handle", &st, NULL);
@@ -769,6 +812,7 @@ gboolean gvir_domain_open_graphics(GVirDomain *dom,
     gboolean ret = FALSE;
 
     g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     priv = dom->priv;
 
@@ -804,6 +848,7 @@ gboolean gvir_domain_suspend (GVirDomain *dom,
     gboolean ret = FALSE;
 
     g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     if (virDomainSuspend(dom->priv->handle) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
@@ -834,6 +879,7 @@ gboolean gvir_domain_save (GVirDomain *dom,
                            GError **err)
 {
     g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     if (virDomainManagedSave(dom->priv->handle, flags) < 0) {
         gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
@@ -889,6 +935,7 @@ void gvir_domain_save_async (GVirDomain *dom,
     DomainSaveData *data;
 
     g_return_if_fail(GVIR_IS_DOMAIN(dom));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
 
     data = g_slice_new0(DomainSaveData);
     data->flags = flags;
@@ -923,6 +970,7 @@ gboolean gvir_domain_save_finish (GVirDomain *dom,
     g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom),
                                                         gvir_domain_save_async),
                          FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
         return FALSE;
diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c
index 883cf92..ecabb41 100644
--- a/libvirt-gobject/libvirt-gobject-interface.c
+++ b/libvirt-gobject/libvirt-gobject-interface.c
@@ -159,11 +159,12 @@ G_DEFINE_BOXED_TYPE(GVirInterfaceHandle, gvir_interface_handle,
 
 const gchar *gvir_interface_get_name(GVirInterface *iface)
 {
-    GVirInterfacePrivate *priv = iface->priv;
     const char *name;
 
-    if (!(name = virInterfaceGetName(priv->handle))) {
-        g_warning("Failed to get interface name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_INTERFACE(iface), NULL);
+
+    if (!(name = virInterfaceGetName(iface->priv->handle))) {
+        g_warning("Failed to get interface name on %p", iface->priv->handle);
         return NULL;
     }
 
@@ -184,9 +185,13 @@ GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface,
                                                guint flags,
                                                GError **err)
 {
-    GVirInterfacePrivate *priv = iface->priv;
+    GVirInterfacePrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_INTERFACE(iface), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = iface->priv;
     if (!(xml = virInterfaceGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_INTERFACE_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-manager.c b/libvirt-gobject/libvirt-gobject-manager.c
index c44e711..d0a2839 100644
--- a/libvirt-gobject/libvirt-gobject-manager.c
+++ b/libvirt-gobject/libvirt-gobject-manager.c
@@ -131,8 +131,12 @@ GVirManager *gvir_manager_new(void)
 void gvir_manager_add_connection(GVirManager *man,
                                  GVirConnection *conn)
 {
-    GVirManagerPrivate *priv = man->priv;
+    GVirManagerPrivate *priv;
+
+    g_return_if_fail(GVIR_IS_MANAGER(man));
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
 
+    priv = man->priv;
     g_mutex_lock(priv->lock);
     g_object_ref(conn);
     priv->connections = g_list_append(priv->connections, conn);
@@ -147,8 +151,12 @@ void gvir_manager_add_connection(GVirManager *man,
 void gvir_manager_remove_connection(GVirManager *man,
                                     GVirConnection *conn)
 {
-    GVirManagerPrivate *priv = man->priv;
+    GVirManagerPrivate *priv;
+
+    g_return_if_fail(GVIR_IS_MANAGER(man));
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
 
+    priv = man->priv;
     g_mutex_lock(priv->lock);
     priv->connections = g_list_remove(priv->connections, conn);
     g_mutex_unlock(priv->lock);
@@ -167,16 +175,18 @@ void gvir_manager_remove_connection(GVirManager *man,
  */
 GList *gvir_manager_get_connections(GVirManager *man)
 {
-    GVirManagerPrivate *priv = man->priv;
+    GList *tmp;
 
-    GList *tmp = priv->connections;
+    g_return_val_if_fail(GVIR_IS_MANAGER(man), NULL);
+
+    tmp = man->priv->connections;
     while (tmp) {
         GVirConnection *conn = tmp->data;
         g_object_ref(conn);
         tmp = tmp->next;
     }
 
-    return g_list_copy(priv->connections);
+    return g_list_copy(man->priv->connections);
 }
 
 
@@ -190,9 +200,12 @@ GList *gvir_manager_get_connections(GVirManager *man)
 GVirConnection *gvir_manager_find_connection_by_uri(GVirManager *man,
                                                     const gchar *uri)
 {
-    GVirManagerPrivate *priv = man->priv;
+    GList *tmp;
 
-    GList *tmp = priv->connections;
+    g_return_val_if_fail(GVIR_IS_MANAGER(man), NULL);
+    g_return_val_if_fail(uri != NULL, NULL);
+
+    tmp = man->priv->connections;
     while (tmp) {
         GVirConnection *conn = tmp->data;
         if (g_strcmp0(gvir_connection_get_uri(conn), uri) == 0)
diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c
index b3db236..00b1ed2 100644
--- a/libvirt-gobject/libvirt-gobject-network-filter.c
+++ b/libvirt-gobject/libvirt-gobject-network-filter.c
@@ -182,11 +182,13 @@ G_DEFINE_BOXED_TYPE(GVirNetworkFilterHandle, gvir_network_filter_handle,
 
 const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter)
 {
-    GVirNetworkFilterPrivate *priv = filter->priv;
     const char *name;
 
-    if (!(name = virNWFilterGetName(priv->handle))) {
-        g_warning("Failed to get network_filter name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_NETWORK_FILTER(filter), NULL);
+
+    if (!(name = virNWFilterGetName(filter->priv->handle))) {
+        g_warning("Failed to get network_filter name on %p",
+                  filter->priv->handle);
         return NULL;
     }
 
@@ -217,9 +219,13 @@ GVirConfigNetworkFilter *gvir_network_filter_get_config
                                  guint flags,
                                  GError **err)
 {
-    GVirNetworkFilterPrivate *priv = filter->priv;
+    GVirNetworkFilterPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_NETWORK_FILTER(filter), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = filter->priv;
     if (!(xml = virNWFilterGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_NETWORK_FILTER_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c
index 17378ec..9625ece 100644
--- a/libvirt-gobject/libvirt-gobject-network.c
+++ b/libvirt-gobject/libvirt-gobject-network.c
@@ -180,11 +180,12 @@ G_DEFINE_BOXED_TYPE(GVirNetworkHandle, gvir_network_handle,
 
 const gchar *gvir_network_get_name(GVirNetwork *network)
 {
-    GVirNetworkPrivate *priv = network->priv;
     const char *name;
 
-    if (!(name = virNetworkGetName(priv->handle))) {
-        g_warning("Failed to get network name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL);
+
+    if (!(name = virNetworkGetName(network->priv->handle))) {
+        g_warning("Failed to get network name on %p", network->priv->handle);
         return NULL;
     }
 
@@ -212,9 +213,13 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network,
                                            guint flags,
                                            GError **err)
 {
-    GVirNetworkPrivate *priv = network->priv;
+    GVirNetworkPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = network->priv;
     if (!(xml = virNetworkGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_NETWORK_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c
index 0a4b6a6..eb314ed 100644
--- a/libvirt-gobject/libvirt-gobject-node-device.c
+++ b/libvirt-gobject/libvirt-gobject-node-device.c
@@ -159,11 +159,13 @@ G_DEFINE_BOXED_TYPE(GVirNodeDeviceHandle, gvir_node_device_handle,
 
 const gchar *gvir_node_device_get_name(GVirNodeDevice *device)
 {
-    GVirNodeDevicePrivate *priv = device->priv;
     const char *name;
 
-    if (!(name = virNodeDeviceGetName(priv->handle))) {
-        g_warning("Failed to get node_device name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_NODE_DEVICE(device), NULL);
+
+    if (!(name = virNodeDeviceGetName(device->priv->handle))) {
+        g_warning("Failed to get node_device name on %p",
+                  device->priv->handle);
         return NULL;
     }
 
@@ -185,9 +187,13 @@ GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device,
                                                   guint flags,
                                                   GError **err)
 {
-    GVirNodeDevicePrivate *priv = device->priv;
+    GVirNodeDevicePrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_NODE_DEVICE(device), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = device->priv;
     if (!(xml = virNodeDeviceGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_NODE_DEVICE_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c
index b0aff13..8bfee88 100644
--- a/libvirt-gobject/libvirt-gobject-secret.c
+++ b/libvirt-gobject/libvirt-gobject-secret.c
@@ -201,9 +201,13 @@ GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret,
                                          guint flags,
                                          GError **err)
 {
-    GVirSecretPrivate *priv = secret->priv;
+    GVirSecretPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_SECRET(secret), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = secret->priv;
     if (!(xml = virSecretGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_SECRET_ERROR,
                                0,
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index e79c8e5..7f50037 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -211,11 +211,12 @@ G_DEFINE_BOXED_TYPE(GVirStoragePoolInfo, gvir_storage_pool_info,
 
 const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
     const char *name;
 
-    if (!(name = virStoragePoolGetName(priv->handle))) {
-        g_warning("Failed to get storage_pool name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+
+    if (!(name = virStoragePoolGetName(pool->priv->handle))) {
+        g_warning("Failed to get storage_pool name on %p", pool->priv->handle);
         return NULL;
     }
 
@@ -244,9 +245,13 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
                                                     guint flags,
                                                     GError **err)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = pool->priv;
     if (!(xml = virStoragePoolGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR,
                                0,
@@ -271,10 +276,14 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
 GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool,
                                                 GError **err)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
     virStoragePoolInfo info;
     GVirStoragePoolInfo *ret;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = pool->priv;
     if (virStoragePoolGetInfo(priv->handle, &info) < 0) {
         if (err)
             *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
@@ -346,7 +355,7 @@ gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
                                    GCancellable *cancellable,
                                    GError **err)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
     GHashTable *vol_hash;
     gchar **volumes = NULL;
     gint nvolumes = 0;
@@ -355,6 +364,12 @@ gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
     virStoragePoolPtr vpool = NULL;
     GError *lerr = NULL;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable),
+                         FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+    priv = pool->priv;
     vpool = priv->handle;
 
     if (virStoragePoolRefresh(vpool, 0) < 0) {
@@ -447,6 +462,9 @@ void gvir_storage_pool_refresh_async(GVirStoragePool *pool,
 {
     GSimpleAsyncResult *res;
 
+    g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     res = g_simple_async_result_new(G_OBJECT(pool),
                                     callback,
                                     user_data,
@@ -495,9 +513,12 @@ static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
  */
 GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
     GList *volumes = NULL;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+
+    priv = pool->priv;
     g_mutex_lock(priv->lock);
     if (priv->volumes != NULL) {
         volumes = g_hash_table_get_values(priv->volumes);
@@ -520,9 +541,12 @@ GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool)
 GVirStorageVol *gvir_storage_pool_get_volume(GVirStoragePool *pool,
                                              const gchar *name)
 {
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
     GVirStorageVol *volume;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+
+    priv = pool->priv;
     g_mutex_lock(priv->lock);
     volume = g_hash_table_lookup(priv->volumes, name);
     if (volume)
@@ -548,12 +572,17 @@ GVirStorageVol *gvir_storage_pool_create_volume
 {
     const gchar *xml;
     virStorageVolPtr handle;
-    GVirStoragePoolPrivate *priv = pool->priv;
+    GVirStoragePoolPrivate *priv;
+
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL);
+    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_VOL(conf), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
 
     g_return_val_if_fail(xml != NULL, NULL);
 
+    priv = pool->priv;
     if (!(handle = virStorageVolCreateXML(priv->handle, xml, 0))) {
         gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR,
                                0,
@@ -593,6 +622,9 @@ gboolean gvir_storage_pool_build (GVirStoragePool *pool,
                                   guint flags,
                                   GError **err)
 {
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
     if (virStoragePoolBuild(pool->priv->handle, flags)) {
         gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR,
                                0,
@@ -644,6 +676,9 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
     GSimpleAsyncResult *res;
     StoragePoolBuildData *data;
 
+    g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     data = g_slice_new0(StoragePoolBuildData);
     data->flags = flags;
 
@@ -675,6 +710,7 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool,
     g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
                                                         gvir_storage_pool_build_async),
                          FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
                                               err))
@@ -695,6 +731,9 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool,
                                   guint flags,
                                   GError **err)
 {
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
     if (virStoragePoolCreate(pool->priv->handle, flags)) {
         gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR,
                                0,
@@ -742,6 +781,9 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
     GSimpleAsyncResult *res;
     StoragePoolBuildData *data;
 
+    g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
     data = g_slice_new0(StoragePoolBuildData);
     data->flags = flags;
 
@@ -773,6 +815,7 @@ gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool,
     g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
                                                         gvir_storage_pool_start_async),
                          FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
     if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
                                               err))
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 9e59576..6f60fcd 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -195,11 +195,12 @@ G_DEFINE_BOXED_TYPE(GVirStorageVolInfo, gvir_storage_vol_info,
 
 const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol)
 {
-    GVirStorageVolPrivate *priv = vol->priv;
     const char *name;
 
-    if (!(name = virStorageVolGetName(priv->handle))) {
-        g_warning("Failed to get storage_vol name on %p", priv->handle);
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL);
+
+    if (!(name = virStorageVolGetName(vol->priv->handle))) {
+        g_warning("Failed to get storage_vol name on %p", vol->priv->handle);
         return NULL;
     }
 
@@ -208,13 +209,15 @@ const gchar *gvir_storage_vol_get_name(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_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL);
+    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
+
+    if (!(path = virStorageVolGetPath(vol->priv->handle))) {
         gvir_set_error(error, GVIR_STORAGE_VOL_ERROR, 0,
                        "Failed to get storage_vol path on %p",
-                       priv->handle);
+                       vol->priv->handle);
         return NULL;
     }
 
@@ -234,9 +237,13 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
                                                   guint flags,
                                                   GError **err)
 {
-    GVirStorageVolPrivate *priv = vol->priv;
+    GVirStorageVolPrivate *priv;
     gchar *xml;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = vol->priv;
     if (!(xml = virStorageVolGetXMLDesc(priv->handle, flags))) {
         gvir_set_error_literal(err, GVIR_STORAGE_VOL_ERROR,
                                0,
@@ -261,10 +268,14 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
 GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol,
                                               GError **err)
 {
-    GVirStorageVolPrivate *priv = vol->priv;
+    GVirStorageVolPrivate *priv;
     virStorageVolInfo info;
     GVirStorageVolInfo *ret;
 
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+    priv = vol->priv;
     if (virStorageVolGetInfo(priv->handle, &info) < 0) {
         if (err)
             *err = gvir_error_new_literal(GVIR_STORAGE_VOL_ERROR,
@@ -295,6 +306,9 @@ gboolean gvir_storage_vol_delete(GVirStorageVol *vol,
                                  guint flags,
                                  GError **err)
 {
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
     if (virStorageVolDelete(vol->priv->handle, flags) < 0) {
         gvir_set_error_literal(err,
                                GVIR_STORAGE_VOL_ERROR,
@@ -322,6 +336,9 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
                                  guint flags,
                                  GError **err)
 {
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
     if (virStorageVolResize(vol->priv->handle, capacity, flags) < 0) {
         gvir_set_error_literal(err,
                                GVIR_STORAGE_VOL_ERROR,
diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c
index 60da4bc..3b98023 100644
--- a/libvirt-gobject/libvirt-gobject-stream.c
+++ b/libvirt-gobject/libvirt-gobject-stream.c
@@ -379,7 +379,9 @@ gvir_stream_receive_all(GVirStream *self,
     int r;
 
     g_return_val_if_fail(GVIR_IS_STREAM(self), -1);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable), -1);
     g_return_val_if_fail(func != NULL, -1);
+    g_return_val_if_fail(error == NULL || *error == NULL, -1);
 
     r = virStreamRecvAll(self->priv->handle, stream_sink, &helper);
     if (r < 0) {
@@ -424,6 +426,8 @@ gssize gvir_stream_send(GVirStream *self,
 
     g_return_val_if_fail(GVIR_IS_STREAM(self), -1);
     g_return_val_if_fail(buffer != NULL, -1);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable), -1);
+    g_return_val_if_fail(error == NULL || *error == NULL, -1);
 
     if (g_cancellable_set_error_if_cancelled (cancellable, error))
         return -1;
@@ -491,7 +495,9 @@ gvir_stream_send_all(GVirStream *self,
     int r;
 
     g_return_val_if_fail(GVIR_IS_STREAM(self), -1);
+    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable), -1);
     g_return_val_if_fail(func != NULL, -1);
+    g_return_val_if_fail(error == NULL || *error == NULL, -1);
 
     r = virStreamSendAll(self->priv->handle, stream_source, &helper);
     if (r < 0) {
-- 
1.7.10.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]