From d0802de1415a22c20ab132c847b08ad81a6c4c19 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 12:32:52 +0200 Subject: [PATCH] randr: ProcRRGetOutputInfo() skip payload assembly when nothing to do If there's no extra payload to send, we can skip the whole payload assembly chain. Signed-off-by: Enrico Weigelt, metux IT consult --- randr/rroutput.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index 7af737480..0be5216b2 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -469,13 +469,14 @@ ProcRRGetOutputInfo(ClientPtr client) .nameLength = output->nameLength }; extraLen = bytes_to_int32(rep.nameLength) << 2; - if (extraLen) { - rep.length += bytes_to_int32(extraLen); - extra = calloc(1, extraLen); - if (!extra) - return BadAlloc; - memcpy(extra, output->name, output->nameLength); - } + if (!extraLen) + goto sendout; + + rep.length += bytes_to_int32(extraLen); + extra = calloc(1, extraLen); + if (!extra) + return BadAlloc; + memcpy(extra, output->name, output->nameLength); } else { rep = (xRRGetOutputInfoReply) { .type = X_Reply, @@ -498,12 +499,13 @@ ProcRRGetOutputInfo(ClientPtr client) output->numModes + output->numUserModes + output->numClones + bytes_to_int32(rep.nameLength)) << 2); - if (extraLen) { - rep.length += bytes_to_int32(extraLen); - extra = calloc(1, extraLen); - if (!extra) - return BadAlloc; - } + if (!extraLen) + goto sendout; + + rep.length += bytes_to_int32(extraLen); + extra = calloc(1, extraLen); + if (!extra) + return BadAlloc; crtcs = (RRCrtc *) extra; modes = (RRMode *) (crtcs + output->numCrtcs); @@ -516,6 +518,7 @@ ProcRRGetOutputInfo(ClientPtr client) if (client->swapped) swapl(&crtcs[i]); } + for (i = 0; i < output->numModes + output->numUserModes; i++) { if (i < output->numModes) modes[i] = output->modes[i]->mode.id; @@ -531,6 +534,7 @@ ProcRRGetOutputInfo(ClientPtr client) } } +sendout: if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); @@ -544,11 +548,10 @@ ProcRRGetOutputInfo(ClientPtr client) swaps(&rep.nClones); swaps(&rep.nameLength); } + WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep); - if (extraLen) { - WriteToClient(client, extraLen, extra); - free(extra); - } + WriteToClient(client, extraLen, extra); + free(extra); return Success; }