mirror of https://github.com/martanne/abduco
Fix file descriptor leakage #30724
This commit is contained in:
parent
678c509f3d
commit
5c7f933dcc
6
server.c
6
server.c
|
|
@ -39,16 +39,18 @@ static int server_create_socket(const char *name) {
|
||||||
return -1;
|
return -1;
|
||||||
socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr.sun_path) + 1;
|
socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr.sun_path) + 1;
|
||||||
mode_t mode = S_IRUSR|S_IWUSR;
|
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)
|
if (bind(fd, (struct sockaddr*)&sockaddr, socklen) == -1)
|
||||||
return -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;
|
goto error;
|
||||||
if (listen(fd, 5) == -1)
|
if (listen(fd, 5) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
return fd;
|
return fd;
|
||||||
error:
|
error:
|
||||||
unlink(sockaddr.sun_path);
|
unlink(sockaddr.sun_path);
|
||||||
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue