From 51c8fd69ec9292f5e18cdc7f60e1716fbd6ae61a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Apr 2008 15:09:40 +0930 Subject: [PATCH] dix: free the unused device classes when closing a device. This also requires to NULL-ify all pointers while we're actually using them, otherwise we'd try to free them twice. --- Xi/exevents.c | 19 +++++++++++++------ dix/devices.c | 7 +++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index 4dd9fceb8..f41250821 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -519,7 +519,8 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) to->key = xcalloc(1, sizeof(KeyClassRec)); if (!to->key) FatalError("[Xi] no memory for class shift.\n"); - } + } else + classes->key = NULL; } oldModKeyMap = to->key->modifierKeyMap; @@ -562,6 +563,8 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) classes = dixLookupPrivate(&to->devPrivates, UnusedClassesPrivateKey); to->valuator = classes->valuator; + if (to->valuator) + classes->valuator = NULL; } to->valuator = xrealloc(to->valuator, sizeof(ValuatorClassRec) + @@ -600,7 +603,8 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) to->button = xcalloc(1, sizeof(ButtonClassRec)); if (!to->button) FatalError("[Xi] no memory for class shift.\n"); - } + } else + classes->button = NULL; } to->button->buttonsDown = 0; @@ -650,7 +654,9 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) to->focus = xcalloc(1, sizeof(FocusClassRec)); if (!to->focus) FatalError("[Xi] no memory for class shift.\n"); - } + } else + classes->focus = NULL; + oldTrace = to->focus->trace; memcpy(to->focus, from->focus, sizeof(FocusClassRec)); to->focus->trace = xrealloc(oldTrace, @@ -680,7 +686,8 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) to->proximity = xcalloc(1, sizeof(ProximityClassRec)); if (!to->proximity) FatalError("[Xi] no memory for class shift.\n"); - } + } else + classes->proximity = NULL; } memcpy(to->proximity, from->proximity, sizeof(ProximityClassRec)); } else if (to->proximity) @@ -703,7 +710,8 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) to->absolute = xcalloc(1, sizeof(AbsoluteClassRec)); if (!to->absolute) FatalError("[Xi] no memory for class shift.\n"); - } + } else + classes->absolute = NULL; } memcpy(to->absolute, from->absolute, sizeof(AbsoluteClassRec)); } else if (to->absolute) @@ -713,7 +721,6 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) classes->absolute = to->absolute; to->absolute = NULL; } - } /** diff --git a/dix/devices.c b/dix/devices.c index d4459168f..fe70e7870 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -775,6 +775,13 @@ CloseDevice(DeviceIntPtr dev) classes = (ClassesPtr)&dev->key; FreeAllDeviceClasses(classes); + if (dev->isMaster) + { + classes = dixLookupPrivate(&dev->devPrivates, UnusedClassesPrivateKey); + FreeAllDeviceClasses(classes); + } + + #ifdef XKB while (dev->xkb_interest) XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);