From: Egbert Eich <eich@suse.de>
Date: Thu Sep 8 14:43:10 2011 +0200
Subject: [PATCH 5/5] Appgroup: Handle an out-of-memory condition gracefully.
Patch-Mainline: to be upstreamed
Git-commit: a2077c974088e6e8a3783f71b3313dff654515ca
References: bnc #716355
Signed-off-by: Egbert Eich <eich@suse.de>

Don't overwrite the client list with NULL if realloc() returned
NULL because of an out-of-memory condition.
Instead fix up the list size and leave Appgroup uninitialized for
this client.

Signed-off-by: Egbert Eich <eich@suse.de>
---
 xorg-server-1.6.5/Xext/appgroup.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/xorg-server-1.6.5/Xext/appgroup.c b/xorg-server-1.6.5/Xext/appgroup.c
index 773d69a..e3474c5 100644
--- a/xorg-server-1.6.5/Xext/appgroup.c
+++ b/xorg-server-1.6.5/Xext/appgroup.c
@@ -150,9 +150,16 @@ static void XagClientStateChange(
 	    }
 	}
 	if (slot == -1) {
+	    pointer ptr;
 	    slot = pAppGrp->nclients++;
-	    pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients, 
+	    ptr = realloc (pAppGrp->clients, 
 				pAppGrp->nclients * sizeof (ClientPtr));
+	    if (!ptr) {
+		pAppGrp->nclients--;
+		pClient->appgroup = NULL;
+		return;
+	    }
+	    pAppGrp->clients = (ClientPtr*)ptr;
 	}
 	pAppGrp->clients[slot] = pClient;
 	break;
