summaryrefslogtreecommitdiff
path: root/src/xcb_util.c
diff options
context:
space:
mode:
authorJulien Cristau <jcristau@debian.org>2008-09-09 04:42:35 +0100
committerJulien Danjou <julien@danjou.info>2008-09-09 14:44:54 +0200
commitf3f8738436d09f7e590b76e22a7a2cc4b16abd1d (patch)
treef46d6e44a74928591146760595ace476767db0b0 /src/xcb_util.c
parentd6d44e1bf09cca8aefbf4ce9875d7f794bf19fb1 (diff)
Fix some fd leaks in _xcb_open_*()
Signed-off-by: Julien Danjou <julien@danjou.info>
Diffstat (limited to 'src/xcb_util.c')
-rw-r--r--src/xcb_util.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/xcb_util.c b/src/xcb_util.c
index c6c5189..6b80c80 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -192,8 +192,10 @@ static int _xcb_open_decnet(const char *host, const char *protocol, const unsign
accessdata.acc_accl = strlen((char *)accessdata.acc_acc);
setsockopt(fd, DNPROTO_NSP, SO_CONACCESS, &accessdata, sizeof(accessdata));
- if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
+ if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
+ close(fd);
return -1;
+ }
return fd;
}
#endif
@@ -238,9 +240,12 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
for(addr = results; addr; addr = addr->ai_next)
{
fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
- if(fd >= 0 && connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0)
- break;
- fd = -1;
+ if(fd >= 0) {
+ if (connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0)
+ break;
+ close(fd);
+ fd = -1;
+ }
}
freeaddrinfo(results);
return fd;
@@ -262,8 +267,10 @@ static int _xcb_open_unix(char *protocol, const char *file)
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(fd == -1)
return -1;
- if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
+ if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
+ close(fd);
return -1;
+ }
return fd;
}