xfree86: don't call xalloc from signal handlers when posting events.
Reviewed-by: Peter Hutterer <peter@cs.unisa.edu.au>
This commit is contained in:
parent
1692dcf197
commit
c68f063be6
|
@ -133,6 +133,11 @@ xf86ProcessCommonOptions(LocalDevicePtr local,
|
||||||
|
|
||||||
/* Backwards compatibility. */
|
/* Backwards compatibility. */
|
||||||
local->history_size = GetMotionHistorySize();
|
local->history_size = GetMotionHistorySize();
|
||||||
|
/* Preallocate xEvent store */
|
||||||
|
if (!xf86Events)
|
||||||
|
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
||||||
|
if (!xf86Events)
|
||||||
|
FatalError("Couldn't allocate event store\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -461,6 +466,8 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
|
||||||
* convenient functions to post events
|
* convenient functions to post events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define MAX_VALUATORS 36 /* XXX from comment in dix/getevents.c */
|
||||||
|
|
||||||
_X_EXPORT void
|
_X_EXPORT void
|
||||||
xf86PostMotionEvent(DeviceIntPtr device,
|
xf86PostMotionEvent(DeviceIntPtr device,
|
||||||
int is_absolute,
|
int is_absolute,
|
||||||
|
@ -470,17 +477,12 @@ xf86PostMotionEvent(DeviceIntPtr device,
|
||||||
{
|
{
|
||||||
va_list var;
|
va_list var;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
static int *valuators = NULL;
|
static int valuators[MAX_VALUATORS];
|
||||||
static int n_valuators = 0;
|
|
||||||
|
|
||||||
if (num_valuators > n_valuators) {
|
if (num_valuators > MAX_VALUATORS) {
|
||||||
xfree (valuators);
|
xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
|
||||||
valuators = NULL;
|
" is greater than MAX_VALUATORS\n", num_valuators);
|
||||||
}
|
return;
|
||||||
|
|
||||||
if (!valuators) {
|
|
||||||
valuators = xcalloc(sizeof(int), num_valuators);
|
|
||||||
n_valuators = num_valuators;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(var, num_valuators);
|
va_start(var, num_valuators);
|
||||||
|
@ -529,9 +531,7 @@ xf86PostMotionEventP(DeviceIntPtr device,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!xf86Events)
|
if (!xf86Events)
|
||||||
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
FatalError("Didn't allocate event store\n");
|
||||||
if (!xf86Events)
|
|
||||||
FatalError("Couldn't allocate event store\n");
|
|
||||||
|
|
||||||
nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
|
nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
|
||||||
flags, first_valuator, num_valuators,
|
flags, first_valuator, num_valuators,
|
||||||
|
@ -555,9 +555,15 @@ xf86PostProximityEvent(DeviceIntPtr device,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list var;
|
va_list var;
|
||||||
int i, nevents, *valuators = NULL;
|
int i, nevents;
|
||||||
|
int valuators[MAX_VALUATORS];
|
||||||
|
|
||||||
valuators = xcalloc(sizeof(int), num_valuators);
|
|
||||||
|
if (num_valuators > MAX_VALUATORS) {
|
||||||
|
xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
|
||||||
|
" is greater than MAX_VALUATORS\n", num_valuators);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_start(var, num_valuators);
|
va_start(var, num_valuators);
|
||||||
for (i = 0; i < num_valuators; i++)
|
for (i = 0; i < num_valuators; i++)
|
||||||
|
@ -565,9 +571,7 @@ xf86PostProximityEvent(DeviceIntPtr device,
|
||||||
va_end(var);
|
va_end(var);
|
||||||
|
|
||||||
if (!xf86Events)
|
if (!xf86Events)
|
||||||
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
FatalError("Didn't allocate event store\n");
|
||||||
if (!xf86Events)
|
|
||||||
FatalError("Couldn't allocate event store\n");
|
|
||||||
|
|
||||||
nevents = GetProximityEvents(xf86Events, device,
|
nevents = GetProximityEvents(xf86Events, device,
|
||||||
is_in ? ProximityIn : ProximityOut,
|
is_in ? ProximityIn : ProximityOut,
|
||||||
|
@ -575,7 +579,6 @@ xf86PostProximityEvent(DeviceIntPtr device,
|
||||||
for (i = 0; i < nevents; i++)
|
for (i = 0; i < nevents; i++)
|
||||||
mieqEnqueue(device, xf86Events + i);
|
mieqEnqueue(device, xf86Events + i);
|
||||||
|
|
||||||
xfree(valuators);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT void
|
_X_EXPORT void
|
||||||
|
@ -588,7 +591,7 @@ xf86PostButtonEvent(DeviceIntPtr device,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list var;
|
va_list var;
|
||||||
int *valuators = NULL;
|
int valuators[MAX_VALUATORS];
|
||||||
int i = 0, nevents = 0;
|
int i = 0, nevents = 0;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -599,18 +602,19 @@ xf86PostButtonEvent(DeviceIntPtr device,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (num_valuators > MAX_VALUATORS) {
|
||||||
|
xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
|
||||||
|
" is greater than MAX_VALUATORS\n", num_valuators);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
valuators = xcalloc(sizeof(int), num_valuators);
|
|
||||||
|
|
||||||
va_start(var, num_valuators);
|
va_start(var, num_valuators);
|
||||||
for (i = 0; i < num_valuators; i++)
|
for (i = 0; i < num_valuators; i++)
|
||||||
valuators[i] = va_arg(var, int);
|
valuators[i] = va_arg(var, int);
|
||||||
va_end(var);
|
va_end(var);
|
||||||
|
|
||||||
if (!xf86Events)
|
if (!xf86Events)
|
||||||
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
FatalError("Didn't allocate event store\n");
|
||||||
if (!xf86Events)
|
|
||||||
FatalError("Couldn't allocate event store\n");
|
|
||||||
|
|
||||||
nevents = GetPointerEvents(xf86Events, device,
|
nevents = GetPointerEvents(xf86Events, device,
|
||||||
is_down ? ButtonPress : ButtonRelease, button,
|
is_down ? ButtonPress : ButtonRelease, button,
|
||||||
|
@ -620,8 +624,6 @@ xf86PostButtonEvent(DeviceIntPtr device,
|
||||||
|
|
||||||
for (i = 0; i < nevents; i++)
|
for (i = 0; i < nevents; i++)
|
||||||
mieqEnqueue(device, xf86Events + i);
|
mieqEnqueue(device, xf86Events + i);
|
||||||
|
|
||||||
xfree(valuators);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT void
|
_X_EXPORT void
|
||||||
|
@ -634,7 +636,8 @@ xf86PostKeyEvent(DeviceIntPtr device,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list var;
|
va_list var;
|
||||||
int i = 0, nevents = 0, *valuators = NULL;
|
int i = 0, nevents = 0;
|
||||||
|
static int valuators[MAX_VALUATORS];
|
||||||
|
|
||||||
/* instil confidence in the user */
|
/* instil confidence in the user */
|
||||||
DebugF("this function has never been tested properly. if things go quite "
|
DebugF("this function has never been tested properly. if things go quite "
|
||||||
|
@ -642,12 +645,9 @@ xf86PostKeyEvent(DeviceIntPtr device,
|
||||||
"broken.\n");
|
"broken.\n");
|
||||||
|
|
||||||
if (!xf86Events)
|
if (!xf86Events)
|
||||||
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
FatalError("Didn't allocate event store\n");
|
||||||
if (!xf86Events)
|
|
||||||
FatalError("Couldn't allocate event store\n");
|
|
||||||
|
|
||||||
if (is_absolute) {
|
if (is_absolute) {
|
||||||
valuators = xcalloc(sizeof(int), num_valuators);
|
|
||||||
va_start(var, num_valuators);
|
va_start(var, num_valuators);
|
||||||
for (i = 0; i < num_valuators; i++)
|
for (i = 0; i < num_valuators; i++)
|
||||||
valuators[i] = va_arg(var, int);
|
valuators[i] = va_arg(var, int);
|
||||||
|
@ -657,7 +657,6 @@ xf86PostKeyEvent(DeviceIntPtr device,
|
||||||
is_down ? KeyPress : KeyRelease,
|
is_down ? KeyPress : KeyRelease,
|
||||||
key_code, first_valuator,
|
key_code, first_valuator,
|
||||||
num_valuators, valuators);
|
num_valuators, valuators);
|
||||||
xfree(valuators);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nevents = GetKeyboardEvents(xf86Events, device,
|
nevents = GetKeyboardEvents(xf86Events, device,
|
||||||
|
@ -686,9 +685,7 @@ xf86PostKeyboardEvent(DeviceIntPtr device,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!xf86Events)
|
if (!xf86Events)
|
||||||
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
|
FatalError("Didn't allocate event store\n");
|
||||||
if (!xf86Events)
|
|
||||||
FatalError("Couldn't allocate event store\n");
|
|
||||||
|
|
||||||
nevents = GetKeyboardEvents(xf86Events, device,
|
nevents = GetKeyboardEvents(xf86Events, device,
|
||||||
is_down ? KeyPress : KeyRelease, key_code);
|
is_down ? KeyPress : KeyRelease, key_code);
|
||||||
|
|
Loading…
Reference in New Issue