After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 724971 - Avoid stale ClutterInputDevice pointers in the device list
Avoid stale ClutterInputDevice pointers in the device list
Status: RESOLVED FIXED
Product: clutter
Classification: Platform
Component: x11
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: clutter-maint
clutter-maint
Depends on:
Blocks:
 
 
Reported: 2014-02-22 20:39 UTC by Carlos Garnacho
Modified: 2014-02-25 09:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
x11: Avoid invalid ClutterInputDevice pointers in the device list (2.37 KB, patch)
2014-02-22 20:40 UTC, Carlos Garnacho
committed Details | Review

Description Carlos Garnacho 2014-02-22 20:39:20 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.
Comment 1 Carlos Garnacho 2014-02-22 20:40:51 UTC
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.
Comment 2 Emmanuele Bassi (:ebassi) 2014-02-24 23:10:40 UTC
Review of attachment 270011 [details] [review]:

looks good, thanks for the patch!
Comment 3 Carlos Garnacho 2014-02-25 09:23:05 UTC
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