From d343cc6289583a7b0d929b82b740499ed588b1ab Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 10 Jun 2013 21:41:24 -0400 Subject: [PATCH] x11: trap errors when calling XIQueryDevice Devices can disappear at any time, causing XIQueryDevice to throw an error. At the same time, plug a memory leak. https://bugzilla.gnome.org/show_bug.cgi?id=701974 --- clutter/x11/clutter-device-manager-xi2.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/clutter/x11/clutter-device-manager-xi2.c b/clutter/x11/clutter-device-manager-xi2.c index 6a06cec..49ee212 100644 --- a/clutter/x11/clutter-device-manager-xi2.c +++ b/clutter/x11/clutter-device-manager-xi2.c @@ -408,10 +408,16 @@ translate_hierarchy_event (ClutterBackendX11 *backend_x11, CLUTTER_NOTE (EVENT, "Hierarchy event: device enabled"); + clutter_x11_trap_x_errors (); info = XIQueryDevice (backend_x11->xdpy, ev->info[i].deviceid, &n_devices); - add_device (manager_xi2, backend_x11, &info[0], FALSE); + clutter_x11_untrap_x_errors (); + if (info != NULL) + { + add_device (manager_xi2, backend_x11, &info[0], FALSE); + XIFreeDeviceInfo (info); + } } else if (ev->info[i].flags & XIDeviceDisabled) { @@ -448,16 +454,24 @@ translate_hierarchy_event (ClutterBackendX11 *backend_x11, /* and attach the slave to the new master if needed */ if (ev->info[i].flags & XISlaveAttached) { + clutter_x11_trap_x_errors (); info = XIQueryDevice (backend_x11->xdpy, ev->info[i].deviceid, &n_devices); - master = g_hash_table_lookup (manager_xi2->devices_by_id, - GINT_TO_POINTER (info->attachment)); - _clutter_input_device_set_associated_device (slave, master); - _clutter_input_device_add_slave (master, slave); - - send_changed = TRUE; - XIFreeDeviceInfo (info); + clutter_x11_untrap_x_errors (); + if (info != NULL) + { + master = g_hash_table_lookup (manager_xi2->devices_by_id, + GINT_TO_POINTER (info->attachment)); + if (master != NULL) + { + _clutter_input_device_set_associated_device (slave, master); + _clutter_input_device_add_slave (master, slave); + + send_changed = TRUE; + } + XIFreeDeviceInfo (info); + } } if (send_changed) -- 1.8.3.1