From 3c4c9938f31755c5a59995fdcfa138c99db76bbf Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Sun, 13 Apr 2008 16:52:14 +0930 Subject: [PATCH] Xi: Fix pointer handling in KeyClassRec copy. We don't free the class anymore, so just store the previous pointers, do the memcpy from the SD and then restore the pointers. Plugs a memleak too, before xkbInfo was never freed. --- Xi/exevents.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index cf0e8984b..aee78c669 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -438,13 +438,36 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to) memcpy(to->field, from->field, sizeof(type)); \ } - ALLOC_COPY_CLASS_IF(key, KeyClassRec); - if (to->key && from->key) + if (from->key) { + KeyCode *oldModKeyMap; + KeySym *oldMap; #ifdef XKB - to->key->xkbInfo = NULL; + struct _XkbSrvInfo *oldXkbInfo; #endif - to->key->curKeySyms.map = NULL; + + if (!to->key) + { + to->key = xcalloc(1, sizeof(KeyClassRec)); + if (!to->key) + FatalError("[Xi] no memory for class shift.\n"); + } + + + oldModKeyMap = to->key->modifierKeyMap; + oldMap = to->key->curKeySyms.map; +#ifdef XKB + oldXkbInfo = to->key->xkbInfo; +#endif + + memcpy(to->key, from->key, sizeof(KeyClassRec)); + + to->key->modifierKeyMap = oldModKeyMap; + to->key->curKeySyms.map = oldMap; +#ifdef XKB + to->key->xkbInfo = oldXkbInfo; +#endif + CopyKeyClass(from, to); } else if (to->key && !from->key) {