Xext: selinux: allocate reply buffer on stack

Simplify reply buffer in SELinuxSendItemsToClient() by putting it on stack.
No need to go through heap and free it later, if the compiler can do all
the work for us.

This also allows further generalizations of reply sending code by upcoming
commits.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2024-07-17 12:19:21 +02:00
parent 6981764c9e
commit 7053fce89f

View File

@@ -345,15 +345,9 @@ static int
SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
int size, int count)
{
int rc, k, pos = 0;
int k, pos = 0;
SELinuxListItemsReply rep;
CARD32 *buf;
buf = calloc(size, sizeof(CARD32));
if (size && !buf) {
rc = BadAlloc;
goto out;
}
CARD32 buf[size];
/* Fill in the buffer */
for (k = 0; k < count; k++) {
@@ -396,11 +390,8 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
WriteToClient(client, size * 4, buf);
/* Free stuff and return */
rc = Success;
free(buf);
out:
SELinuxFreeItems(items, count);
return rc;
return Success;
}
static int