GNOME Bugzilla – Bug 724971
Avoid stale ClutterInputDevice pointers in the device list
Last modified: 2014-02-25 09:23:08 UTC
There is a couple of cases in clutter-device-manager-xi2.c where add_device() is being called too eagerly, which due to the way it maintains hashtable and device lists, it may result in stale pointers in the list if add_device() is called several times for a same device ID. Clutter does generally a good deal at keeping the device list meaningful, although there's still a couple of cases where this might happen. - constructed() adds devices without any checks, so it may also add disabled devices that would get added again when a XIHierarchyEvent with the XIDeviceEnabled flag is received for it. - A quite more racy case, seen in gnome-shell. If it is started on a tty, and you switch to the one it's been spawned on, ClutterDeviceManager constructed() may happen sortly before the event loop gets to receive the XIHierarchyEvents triggered by the tty switch. so devices are first seen as enabled, and then XIDeviceEnabled hierarchy events are gotten right after. I'm attaching a patch to prevent double additions in these cases.
Created attachment 270011 [details] [review] x11: Avoid invalid ClutterInputDevice pointers in the device list Due to the way add_device() invariably adds to the master/slave device lists, while keeping ClutterInputDevices 1:1 with device IDs, it may leave invalid pointers in the list if add_device() is called multiple times for the same device ID. There are two situations where this may happen: 1) If devices are disabled and later enabled: devices are added invariably to the master/slave lists on constructed(), but then on XIDeviceEnabled they'd get added yet again. 2) Racy cases where the ClutterDeviceManager is created around the same time XIHierarchyEvents are sent. When getting the XIDeviceInfo on constructed(), these devices may already appear as enabled, even though XIDeviceEnabled is seen through XIHierarchyEvents processed in the event loop sortly after. This last case can be seen when starting gnome-shell on a different tty, and entering in the one it's been spawned on, clutter initialization happens around the same time devices are added back because of the tty switch, and multiple extra ClutterInputDevices are created.
Review of attachment 270011 [details] [review]: looks good, thanks for the patch!
Cheers :). It's been pushed to master and clutter-1.18 Attachment 270011 [details] pushed as 45935fb - x11: Avoid invalid ClutterInputDevice pointers in the device list