summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2022-11-09 14:33:07 +0100
committerJens Georg <mail@jensge.org>2022-11-09 14:33:07 +0100
commit7f75ae9f102db0825a919fc8244cdb65ed8d34e4 (patch)
tree0c53bf3894de32fe18897525b6ff72b4cf97070f
parent8886f95134d95e49d859512fc0c2c62ed63a72b2 (diff)
downloadgupnp-tools-7f75ae9f102db0825a919fc8244cdb65ed8d34e4.tar.gz
universal-cp: Do not crash if device disappears
Properly handle introspection errors and check for validity of iter if introspection finishes Fixes #24
-rw-r--r--src/universal-cp/device-treeview.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/universal-cp/device-treeview.c b/src/universal-cp/device-treeview.c
index 79a9e43..737d093 100644
--- a/src/universal-cp/device-treeview.c
+++ b/src/universal-cp/device-treeview.c
@@ -574,7 +574,7 @@ got_introspection (GObject *source, GAsyncResult *res, gpointer user_data)
{
GtkTreeModel *model;
GtkTreeIter *service_iter;
- GError *error = NULL;
+ g_autoptr (GError) error = NULL;
GUPnPServiceIntrospection *introspection =
gupnp_service_info_introspect_finish (
@@ -582,17 +582,32 @@ got_introspection (GObject *source, GAsyncResult *res, gpointer user_data)
res,
&error);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ return;
+ }
+
+ if (error != NULL) {
+ g_warning ("Failed to get introspection for device: %s",
+ error->message);
+
+ return;
+ }
+
service_iter = (GtkTreeIter *) user_data;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
g_assert (model != NULL);
+ if (!gtk_tree_store_iter_is_valid (GTK_TREE_STORE (model),
+ service_iter)) {
+ goto out;
+ }
+
append_introspection (GUPNP_SERVICE_PROXY (source),
introspection,
GTK_TREE_STORE (model),
service_iter);
- g_slice_free (GtkTreeIter, service_iter);
if (introspection != NULL) {
g_object_unref (introspection);
@@ -601,6 +616,8 @@ got_introspection (GObject *source, GAsyncResult *res, gpointer user_data)
GUPNP_SERVICE_PROXY (source),
TRUE);
}
+out:
+ g_slice_free (GtkTreeIter, service_iter);
}
static void