(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:
Enrico Weigelt, metux IT consult 2024-07-11 09:22:12 +02:00
parent e7262542d5
commit 63f510ebf2
3 changed files with 4 additions and 11 deletions

View File

@ -153,7 +153,6 @@ int
ProcXGetDeviceControl(ClientPtr client) ProcXGetDeviceControl(ClientPtr client)
{ {
int rc, total_length = 0; int rc, total_length = 0;
char *savbuf;
DeviceIntPtr dev; DeviceIntPtr dev;
REQUEST(xGetDeviceControlReq); REQUEST(xGetDeviceControlReq);
@ -186,7 +185,7 @@ ProcXGetDeviceControl(ClientPtr client)
char *buf = calloc(1, total_length); char *buf = calloc(1, total_length);
if (!buf) if (!buf)
return BadAlloc; return BadAlloc;
savbuf = buf; char *savbuf = buf;
switch (stuff->control) { switch (stuff->control) {
case DEVICE_RESOLUTION: case DEVICE_RESOLUTION:

View File

@ -244,7 +244,6 @@ int
ProcXGetFeedbackControl(ClientPtr client) ProcXGetFeedbackControl(ClientPtr client)
{ {
int rc, total_length = 0; int rc, total_length = 0;
char *savbuf;
DeviceIntPtr dev; DeviceIntPtr dev;
KbdFeedbackPtr k; KbdFeedbackPtr k;
PtrFeedbackPtr p; PtrFeedbackPtr p;
@ -298,7 +297,7 @@ ProcXGetFeedbackControl(ClientPtr client)
char *buf = (char *) calloc(1, total_length); char *buf = (char *) calloc(1, total_length);
if (!buf) if (!buf)
return BadAlloc; return BadAlloc;
savbuf = buf; char *savbuf = buf;
for (k = dev->kbdfeed; k; k = k->next) for (k = dev->kbdfeed; k; k = k->next)
CopySwapKbdFeedback(client, k, &buf); CopySwapKbdFeedback(client, k, &buf);
@ -322,6 +321,5 @@ ProcXGetFeedbackControl(ClientPtr client)
} }
WriteToClient(client, sizeof(xGetFeedbackControlReply), &rep); WriteToClient(client, sizeof(xGetFeedbackControlReply), &rep);
WriteToClient(client, total_length, savbuf); WriteToClient(client, total_length, savbuf);
free(savbuf);
return Success; return Success;
} }

View File

@ -342,7 +342,6 @@ ProcXIGetSelectedEvents(ClientPtr client)
{ {
int rc, i; int rc, i;
WindowPtr win; WindowPtr win;
char *buffer = NULL;
OtherInputMasks *masks; OtherInputMasks *masks;
InputClientsPtr others = NULL; InputClientsPtr others = NULL;
xXIEventMask *evmask = NULL; xXIEventMask *evmask = NULL;
@ -374,10 +373,8 @@ ProcXIGetSelectedEvents(ClientPtr client)
if (!others) if (!others)
goto finish; goto finish;
buffer = char buffer[MAXDEVICES * (sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE))];
calloc(MAXDEVICES, sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE)); memset(buffer, 0, sizeof(buffer));
if (!buffer)
return BadAlloc;
evmask = (xXIEventMask *) buffer; evmask = (xXIEventMask *) buffer;
for (i = 0; i < MAXDEVICES; i++) { for (i = 0; i < MAXDEVICES; i++) {
@ -423,6 +420,5 @@ finish: ;
WriteToClient(client, sizeof(xXIGetSelectedEventsReply), &rep); WriteToClient(client, sizeof(xXIGetSelectedEventsReply), &rep);
WriteToClient(client, length * 4, buffer); WriteToClient(client, length * 4, buffer);
free(buffer);
return Success; return Success;
} }