check malloc return
 failed mallocs will cause segfaults, so add check
 also free already allocated memory

 Signed-off-by: Walter Harms <[email protected]>
---
 src/connect.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/connect.c b/src/connect.c
index 276a356..b61449e 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -193,8 +193,8 @@ IceOpenConnection (

     iceConn->connect_to_me = NULL;
     iceConn->protosetup_to_me = NULL;
-
-    if ((iceConn->inbuf = iceConn->inbufptr = malloc (ICE_INBUFSIZE)) == NULL)
+    iceConn->inbuf = iceConn->inbufptr = malloc (ICE_INBUFSIZE);
+    if ( iceConn->inbuf == NULL)
     {
        _IceFreeConnection (iceConn);
        strncpy (errorStringRet, "Can't malloc", errorLength);
@@ -202,9 +202,10 @@ IceOpenConnection (
     }

     iceConn->inbufmax = iceConn->inbuf + ICE_INBUFSIZE;
-
-    if ((iceConn->outbuf = iceConn->outbufptr = calloc (1, ICE_OUTBUFSIZE)) == 
NULL)
+    iceConn->outbuf = iceConn->outbufptr = calloc (1, ICE_OUTBUFSIZE);
+    if ( iceConn->outbuf == NULL)
     {
+        free(iceConn->inbuf);
        _IceFreeConnection (iceConn);
        strncpy (errorStringRet, "Can't malloc", errorLength);
        return (NULL);
@@ -225,6 +226,14 @@ IceOpenConnection (
     iceConn->connect_to_you = malloc (sizeof (_IceConnectToYouInfo));
     iceConn->connect_to_you->auth_active = 0;

+    if (!iceConn->connect_to_you) {
+        free(iceConn->outbuf);
+        free(iceConn->inbuf);
+       _IceFreeConnection (iceConn);
+       strncpy (errorStringRet, "Can't malloc", errorLength);
+       return (NULL);
+    }
+
     /*
      * Send our byte order.
      */
@@ -467,6 +476,8 @@ ConnectToPeer (char *networkIdsList, char 
**actualConnectionRet)
     else
     {
        address = malloc (len + 1);
+       if (!address)
+        return (NULL);
        address_size = len;
     }

-- 
2.1.4

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to