--- /usr/src/coe/BUILD/xorg-x11-6.8.2-37/xc/programs/Xserver/Xext/appgroup.c 2004-04-23 13:44:41.000000000 -0500 +++ Xext/appgroup.c 2006-05-16 15:40:07.608659992 -0500 @@ -96,7 +96,7 @@ int XagAppGroupFree( if (pAppGrp->leader) for (i = 0; i < pAppGrp->nclients; i++) { - pAppGrp->clients[i]->appgroup = NULL; + if (NULL == pAppGrp->clients[i]) continue; CloseDownClient (pAppGrp->clients[i]); } @@ -130,6 +130,7 @@ void XagClientStateChange( ClientPtr pClient = pci->client; AppGroupPtr pAppGrp; XID authId = 0; + int slot; if (!pClient->appgroup) { switch (pClient->clientState) { @@ -191,16 +192,22 @@ void XagClientStateChange( case ClientStateInitial: case ClientStateCheckedSecurity: + slot = -1; /* see the comment above about Initial vs. CheckedSecurity */ - { + if (0 != pAppGrp->nclients) { /* if this client already in AppGroup, don't add it again */ int i; for (i = 0; i < pAppGrp->nclients; i++) if (pClient == pAppGrp->clients[i]) return; + if (-1 == slot && NULL == pAppGrp->clients[i]) + slot = i; + } + if (-1 == slot) { + slot = pAppGrp->nclients++; + pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients, + pAppGrp->nclients * sizeof (ClientPtr)); } - pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients, - ++pAppGrp->nclients * sizeof (ClientPtr)); - pAppGrp->clients[pAppGrp->nclients - 1] = pClient; + pAppGrp->clients[slot] = pClient; pClient->appgroup = pAppGrp; break; @@ -213,10 +220,6 @@ void XagClientStateChange( pAppGrp->clients[i] = NULL; break; } - for (i = 0; i < pAppGrp->nclients; i++) - if (pAppGrp->clients[i] == NULL && i + 1 < pAppGrp->nclients) - pAppGrp->clients[i] = pAppGrp->clients[i + 1]; - pAppGrp->nclients--; } pClient->appgroup = NULL; /* redundant, pClient will be freed */ break;