Skip to content

Commit

Permalink
fix(server): file descriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbu committed Apr 12, 2024
1 parent 9abecee commit 635007f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ static bool open_server(server_t *s)
.sin_port = htons(s->port),
.sin_addr.s_addr = INADDR_ANY,
};
if (bind(s->fd, (struct sockaddr *)&s->addr, sizeof(s->addr)) < 0) {
perror("bind");
return false;
}
if (listen(s->fd, 5) < 0) {
perror("listen");
if (bind(s->fd, (struct sockaddr *)&s->addr, sizeof(s->addr)) < 0 ||
listen(s->fd, 5) < 0) {
perror("bind/listen");
close(s->fd);
return false;
}
return true;
Expand Down

0 comments on commit 635007f

Please sign in to comment.