From 7053fce89fe3ce7e50a9be6dd783faa5eff91887 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 17 Jul 2024 12:19:21 +0200 Subject: [PATCH] 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 --- Xext/xselinux_ext.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c index 5bfb9a84bb..ac1e7ac41e 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -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