From 27356a45b4f6bad4d0bbf356e6d976d0c8dd257b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 27 Feb 2012 17:22:16 +1000 Subject: [PATCH] dix: only allocate unused classes for master devices Slave devices don't need these and the matching code in CloseDevice() has a IsMaster() condition on freeing these, causing a leak. ==16111== 384 bytes in 4 blocks are definitely lost in loss record 72 of 105 ==16111== at 0x4C28BB4: calloc (vg_replace_malloc.c:467) ==16111== by 0x42AEE2: AllocDevicePair (devices.c:2707) ==16111== by 0x4BAA27: AllocXTestDevice (xtest.c:617) ==16111== by 0x4BA89A: InitXTestDevices (xtest.c:570) ==16111== by 0x425F5E: InitCoreDevices (devices.c:690) ==16111== by 0x5ACB2D: main (main.c:257) Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- dix/devices.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index be236dd..5f98afc 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2766,9 +2766,10 @@ AllocDevicePair(ClientPtr client, const char *name, keyboard->type = (master) ? MASTER_KEYBOARD : SLAVE; /* The ClassesRec stores the device classes currently not used. */ - pointer->unused_classes = calloc(1, sizeof(ClassesRec)); - - keyboard->unused_classes = calloc(1, sizeof(ClassesRec)); + if (IsMaster(pointer)) { + pointer->unused_classes = calloc(1, sizeof(ClassesRec)); + keyboard->unused_classes = calloc(1, sizeof(ClassesRec)); + } *ptr = pointer; -- 2.7.4