Replace some input devPrivates with regular struct fields

In the process, fixes a memory leak in CloseDevice, and an unchecked
memory allocation in InitializePredictableAccelerationProperties.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
Keith Packard 2010-04-29 12:24:49 -07:00
commit 65e961fcc1
6 changed files with 47 additions and 92 deletions

View file

@ -89,13 +89,6 @@ SOFTWARE.
* This file handles input device-related stuff.
*/
static int CoreDevicePrivateKeyIndex;
DevPrivateKey CoreDevicePrivateKey = &CoreDevicePrivateKeyIndex;
/* Used to store classes currently not in use by an MD */
static int UnusedClassesPrivateKeyIndex;
DevPrivateKey UnusedClassesPrivateKey = &UnusedClassesPrivateKeyIndex;
static void RecalculateMasterButtons(DeviceIntPtr slave);
/**
@ -852,8 +845,9 @@ CloseDevice(DeviceIntPtr dev)
if (IsMaster(dev))
{
classes = dixLookupPrivate(&dev->devPrivates, UnusedClassesPrivateKey);
classes = dev->unused_classes;
FreeAllDeviceClasses(classes);
xfree(classes);
}
if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
@ -2465,7 +2459,6 @@ AllocDevicePair (ClientPtr client, char* name,
{
DeviceIntPtr pointer;
DeviceIntPtr keyboard;
ClassesPtr classes;
*ptr = *keybd = NULL;
pointer = AddInputDevice(client, ptr_proc, TRUE);
@ -2511,12 +2504,9 @@ AllocDevicePair (ClientPtr client, char* name,
keyboard->last.slave = NULL;
keyboard->type = (master) ? MASTER_KEYBOARD : SLAVE;
/* The ClassesRec stores the device classes currently not used. */
classes = xcalloc(1, sizeof(ClassesRec));
dixSetPrivate(&pointer->devPrivates, UnusedClassesPrivateKey, classes);
classes = xcalloc(1, sizeof(ClassesRec));
dixSetPrivate(&keyboard->devPrivates, UnusedClassesPrivateKey, classes);
pointer->unused_classes = xcalloc(1, sizeof(ClassesRec));
keyboard->unused_classes = xcalloc(1, sizeof(ClassesRec));
*ptr = pointer;
*keybd = keyboard;

View file

@ -1408,12 +1408,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode)
ComputeFreezes();
}
/* Only ever used if a grab is called on an attached slave device. */
static int GrabPrivateKeyIndex;
static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex;
/**
* Save the device's master device in the devPrivates. This needs to be done
* Save the device's master device id. This needs to be done
* if a client directly grabs a slave device that is attached to a master. For
* the duration of the grab, the device is detached, ungrabbing re-attaches it
* though.
@ -1424,35 +1420,28 @@ static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex;
static void
DetachFromMaster(DeviceIntPtr dev)
{
intptr_t id;
if (!dev->u.master)
return;
id = dev->u.master->id;
dev->saved_master_id = dev->u.master->id;
dixSetPrivate(&dev->devPrivates, GrabPrivateKey, (void *)id);
AttachDevice(NULL, dev, NULL);
}
static void
ReattachToOldMaster(DeviceIntPtr dev)
{
int id;
void *p;
DeviceIntPtr master = NULL;
if (IsMaster(dev))
return;
p = dixLookupPrivate(&dev->devPrivates, GrabPrivateKey);
id = (intptr_t) p; /* silence gcc warnings */
dixLookupDevice(&master, id, serverClient, DixUseAccess);
dixLookupDevice(&master, dev->saved_master_id, serverClient, DixUseAccess);
if (master)
{
AttachDevice(serverClient, dev, master);
dixSetPrivate(&dev->devPrivates, GrabPrivateKey, NULL);
dev->saved_master_id = 0;
}
}

View file

@ -83,8 +83,6 @@ GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
/* some int which is not a profile number */
#define PROFILE_UNINITIALIZE (-100)
/* number of properties for predictable acceleration */
#define NPROPS_PREDICTABLE_ACCEL 4
/**
* Init struct so it should match the average case
@ -323,26 +321,18 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL);
}
static int AccelPropHandlerPrivateKeyIndex;
DevPrivateKey AccelPropHandlerPrivateKey = &AccelPropHandlerPrivateKeyIndex;
BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr dev)
{
DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev);
long *prop_handlers;
if(!vel)
return FALSE;
prop_handlers = xalloc(NPROPS_PREDICTABLE_ACCEL * sizeof(long));
prop_handlers[0] = AccelInitProfileProperty(dev, vel);
prop_handlers[1] = AccelInitDecelProperty(dev, vel);
prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel);
prop_handlers[3] = AccelInitScaleProperty(dev, vel);
dixSetPrivate(&dev->devPrivates, AccelPropHandlerPrivateKey,
prop_handlers);
vel->prop_handlers[0] = AccelInitProfileProperty(dev, vel);
vel->prop_handlers[1] = AccelInitDecelProperty(dev, vel);
vel->prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel);
vel->prop_handlers[3] = AccelInitScaleProperty(dev, vel);
return TRUE;
}
@ -350,8 +340,8 @@ InitializePredictableAccelerationProperties(DeviceIntPtr dev)
BOOL
DeletePredictableAccelerationProperties(DeviceIntPtr dev)
{
DeviceVelocityPtr vel;
Atom prop;
long *prop_handlers;
int i;
prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
@ -363,13 +353,10 @@ DeletePredictableAccelerationProperties(DeviceIntPtr dev)
prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
XIDeleteDeviceProperty(dev, prop, FALSE);
prop_handlers = dixLookupPrivate(&dev->devPrivates,
AccelPropHandlerPrivateKey);
dixSetPrivate(&dev->devPrivates, AccelPropHandlerPrivateKey, NULL);
for (i = 0; prop_handlers && i < NPROPS_PREDICTABLE_ACCEL; i++)
XIUnregisterPropertyHandler(dev, prop_handlers[i]);
xfree(prop_handlers);
vel = GetDevicePredictableAccelData(dev);
for (i = 0; vel && i < NPROPS_PREDICTABLE_ACCEL; i++)
if (vel->prop_handlers[i])
XIUnregisterPropertyHandler(dev, vel->prop_handlers[i]);
return TRUE;
}