(submit/cleanup-xi) Xi: use stack allocation for temporary buffers
Small buffers easily fit on stack, which is much faster (just moving SP), and alloca()'ed buffers are cleaned up automatically on function leave, no extra free() needed. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
e7262542d5
commit
63f510ebf2
|
@ -153,7 +153,6 @@ int
|
|||
ProcXGetDeviceControl(ClientPtr client)
|
||||
{
|
||||
int rc, total_length = 0;
|
||||
char *savbuf;
|
||||
DeviceIntPtr dev;
|
||||
|
||||
REQUEST(xGetDeviceControlReq);
|
||||
|
@ -186,7 +185,7 @@ ProcXGetDeviceControl(ClientPtr client)
|
|||
char *buf = calloc(1, total_length);
|
||||
if (!buf)
|
||||
return BadAlloc;
|
||||
savbuf = buf;
|
||||
char *savbuf = buf;
|
||||
|
||||
switch (stuff->control) {
|
||||
case DEVICE_RESOLUTION:
|
||||
|
|
|
@ -244,7 +244,6 @@ int
|
|||
ProcXGetFeedbackControl(ClientPtr client)
|
||||
{
|
||||
int rc, total_length = 0;
|
||||
char *savbuf;
|
||||
DeviceIntPtr dev;
|
||||
KbdFeedbackPtr k;
|
||||
PtrFeedbackPtr p;
|
||||
|
@ -298,7 +297,7 @@ ProcXGetFeedbackControl(ClientPtr client)
|
|||
char *buf = (char *) calloc(1, total_length);
|
||||
if (!buf)
|
||||
return BadAlloc;
|
||||
savbuf = buf;
|
||||
char *savbuf = buf;
|
||||
|
||||
for (k = dev->kbdfeed; k; k = k->next)
|
||||
CopySwapKbdFeedback(client, k, &buf);
|
||||
|
@ -322,6 +321,5 @@ ProcXGetFeedbackControl(ClientPtr client)
|
|||
}
|
||||
WriteToClient(client, sizeof(xGetFeedbackControlReply), &rep);
|
||||
WriteToClient(client, total_length, savbuf);
|
||||
free(savbuf);
|
||||
return Success;
|
||||
}
|
||||
|
|
|
@ -342,7 +342,6 @@ ProcXIGetSelectedEvents(ClientPtr client)
|
|||
{
|
||||
int rc, i;
|
||||
WindowPtr win;
|
||||
char *buffer = NULL;
|
||||
OtherInputMasks *masks;
|
||||
InputClientsPtr others = NULL;
|
||||
xXIEventMask *evmask = NULL;
|
||||
|
@ -374,10 +373,8 @@ ProcXIGetSelectedEvents(ClientPtr client)
|
|||
if (!others)
|
||||
goto finish;
|
||||
|
||||
buffer =
|
||||
calloc(MAXDEVICES, sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE));
|
||||
if (!buffer)
|
||||
return BadAlloc;
|
||||
char buffer[MAXDEVICES * (sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE))];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
evmask = (xXIEventMask *) buffer;
|
||||
for (i = 0; i < MAXDEVICES; i++) {
|
||||
|
@ -423,6 +420,5 @@ finish: ;
|
|||
WriteToClient(client, sizeof(xXIGetSelectedEventsReply), &rep);
|
||||
WriteToClient(client, length * 4, buffer);
|
||||
|
||||
free(buffer);
|
||||
return Success;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue