[PATCH libICE 07/13] add check for malloc

walter harms wharms at bfs.de
Wed Oct 18 16:01:07 UTC 2017


 add check for malloc and a bit untangling
 Signed-off-by: Walter Harms <wharms at bfs.de>

---
 src/watch.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/watch.c b/src/watch.c
index abbc265..c60d0c1 100644
--- a/src/watch.c
+++ b/src/watch.c
@@ -48,7 +48,8 @@ IceAddConnectionWatch (
     _IceWatchProc	*newWatchProc;
     int			i;

-    if ((newWatchProc = malloc (sizeof (_IceWatchProc))) == NULL)
+    newWatchProc = malloc (sizeof (_IceWatchProc));
+    if ( !newWatchProc )
     {
 	return (0);
     }
@@ -75,7 +76,11 @@ IceAddConnectionWatch (
     {
 	_IceWatchedConnection *newWatchedConn =
 	    malloc (sizeof (_IceWatchedConnection));
-
+	if (!newWatchedConn)
+	  {
+	    IceRemoveConnectionWatch(watchProc,clientData);
+	    return (0);
+	  }
 	newWatchedConn->iceConn = _IceConnectionObjs[i];
 	newWatchedConn->next = NULL;

@@ -86,6 +91,7 @@ IceAddConnectionWatch (
     }

     return (1);
+
 }


@@ -143,6 +149,9 @@ _IceConnectionOpened (
 	    malloc (sizeof (_IceWatchedConnection));
 	_IceWatchedConnection *watchedConn;

+	if (!newWatchedConn)
+	  return ;
+
 	watchedConn = watchProc->watched_connections;
 	while (watchedConn && watchedConn->next)
 	    watchedConn = watchedConn->next;
-- 
2.1.4



More information about the xorg-devel mailing list