abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 5c7f933dcc3866229729b88c20a82a2ccc62b844
parent 678c509f3d4db88dcc3a5acfcc05170ba855d1a9
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 16 Feb 2015 22:42:01 +0100

Fix file descriptor leakage #30724

Diffstat:
server.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/server.c b/server.c @@ -39,16 +39,18 @@ static int server_create_socket(const char *name) { return -1; socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr.sun_path) + 1; mode_t mode = S_IRUSR|S_IWUSR; - fchmod(fd, mode); + if (fchmod(fd, mode) == -1) + goto error; if (bind(fd, (struct sockaddr*)&sockaddr, socklen) == -1) return -1; - if (fchmod(fd, mode) == -1 && chmod(sockaddr.sun_path, mode) == -1) + if (fchmod(fd, mode) == -1 || chmod(sockaddr.sun_path, mode) == -1) goto error; if (listen(fd, 5) == -1) goto error; return fd; error: unlink(sockaddr.sun_path); + close(fd); return -1; }