diff --git a/Xext/xres.c b/Xext/xres.c index ceb7b57d6..f439e0627 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -337,28 +337,27 @@ ProcXResQueryClientResources(ClientPtr client) swapl(&rep.num_types); } - WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep); + xXResType *scratch = calloc(sizeof(xXResType), num_types); + if (!scratch) { + free(counts); + return BadAlloc; + } - if (num_types) { - xXResType scratch; + for (int i = 0; i < num_types; i++) { + scratch[i].resource_type = resourceTypeAtom(i + 1); + scratch[i].count = counts[i]; - for (int i = 0; i < lastResourceType; i++) { - if (!counts[i]) - continue; - - scratch.resource_type = resourceTypeAtom(i + 1); - scratch.count = counts[i]; - - if (client->swapped) { - swapl(&scratch.resource_type); - swapl(&scratch.count); - } - WriteToClient(client, sz_xXResType, &scratch); + if (client->swapped) { + swapl(&scratch[i].resource_type); + swapl(&scratch[i].count); } } free(counts); + WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep); + WriteToClient(client, sizeof(scratch), scratch); + free(scratch); return Success; }