[PATCH] Fix memory/resource leaks in libxtrans

Alan Hourihane alanh at fairlite.co.uk
Thu Dec 1 04:04:22 PST 2011


Re-sending, sorry missed the [PATCH] off the subject line...

Fix some resource & memory leaks in libxtrans.

Signed-off-by: Alan Hourihane <alanh at vmware.com>
---
diff --git a/Xtrans.c b/Xtrans.c
index d90a8cc..ce1d7ba 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -548,6 +548,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char
*port)
     if (ciptr == NULL)
     {
     PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0);
+    xfree(save_port);
     return NULL;
     }
 
diff --git a/Xtranssock.c b/Xtranssock.c
index 78471b3..3aec1f8 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -496,6 +496,7 @@ TRANS(SocketReopen) (int i, int type, int fd, char
*port)
 
     if ((addr = (struct sockaddr *) xcalloc (1, portlen + 2)) == NULL) {
     PRMSG (1, "SocketReopen: malloc(addr) failed\n", 0, 0, 0);
+    xfree (ciptr);
     return NULL;
     }
     ciptr->addr = (char *) addr;
@@ -503,6 +504,8 @@ TRANS(SocketReopen) (int i, int type, int fd, char
*port)
 
     if ((ciptr->peeraddr = (char *) xcalloc (1, portlen + 2)) == NULL) {
     PRMSG (1, "SocketReopen: malloc(portaddr) failed\n", 0, 0, 0);
+    xfree (addr);
+    xfree (ciptr);
     return NULL;
     }
     ciptr->peeraddrlen = portlen + 2;
diff --git a/Xtransutil.c b/Xtransutil.c
index 42f09c4..d17d700 100644
--- a/Xtransutil.c
+++ b/Xtransutil.c
@@ -586,6 +586,7 @@ trans_mkdir(const char *path, int mode)
             if (fstat(fd, &fbuf) == -1) {
             PRMSG(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
                   path, errno, 0);
+            close(fd);
             return -1;
             }
             /*
@@ -597,6 +598,7 @@ trans_mkdir(const char *path, int mode)
             buf.st_ino != fbuf.st_ino) {
             PRMSG(1, "mkdir: ERROR: inode for %s changed\n",
                   path, 0, 0);
+            close(fd);
             return -1;
             }
             if (updateOwner && fchown(fd, 0, 0) == 0)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: xtrans.patch
Type: text/x-patch
Size: 1609 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20111201/fb654013/attachment.bin>


More information about the xorg-devel mailing list