aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/dix/devices.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/dix/devices.c')
-rw-r--r--xorg-server/dix/devices.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/xorg-server/dix/devices.c b/xorg-server/dix/devices.c
index 92b95ed69..b002150d0 100644
--- a/xorg-server/dix/devices.c
+++ b/xorg-server/dix/devices.c
@@ -877,13 +877,43 @@ CloseDevice(DeviceIntPtr dev)
}
/**
+ * Shut down all devices of one list and free all resources.
+ */
+static
+void
+CloseDeviceList(DeviceIntPtr *listHead)
+{
+ /* Used to mark devices that we tried to free */
+ Bool freedIds[MAXDEVICES];
+ DeviceIntPtr dev;
+ int i;
+
+ if (listHead == NULL)
+ return;
+
+ for (i = 0; i < MAXDEVICES; i++)
+ freedIds[i] = FALSE;
+
+ dev = *listHead;
+ while (dev != NULL)
+ {
+ freedIds[dev->id] = TRUE;
+ DeleteInputDeviceRequest(dev);
+
+ dev = *listHead;
+ while (dev != NULL && freedIds[dev->id])
+ dev = dev->next;
+ }
+}
+
+/**
* Shut down all devices, free all resources, etc.
* Only useful if you're shutting down the server!
*/
void
CloseDownDevices(void)
{
- DeviceIntPtr dev, next;
+ DeviceIntPtr dev;
/* Float all SDs before closing them. Note that at this point resources
* (e.g. cursors) have been freed already, so we can't just call
@@ -896,16 +926,8 @@ CloseDownDevices(void)
dev->u.master = NULL;
}
- for (dev = inputInfo.devices; dev; dev = next)
- {
- next = dev->next;
- DeleteInputDeviceRequest(dev);
- }
- for (dev = inputInfo.off_devices; dev; dev = next)
- {
- next = dev->next;
- DeleteInputDeviceRequest(dev);
- }
+ CloseDeviceList(&inputInfo.devices);
+ CloseDeviceList(&inputInfo.off_devices);
CloseDevice(inputInfo.pointer);
CloseDevice(inputInfo.keyboard);