Skip to content

Commit

Permalink
socket: Do not call close() callback twice
Browse files Browse the repository at this point in the history
The close() callback was called unconditional, thus it got called
even if the file descriptor is already unset.
  • Loading branch information
cfconrad committed May 30, 2022
1 parent 9e7b505 commit df32481
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/socket.c
Expand Up @@ -271,12 +271,13 @@ ni_socket_wrap(int fd, int sotype)
static void
__ni_socket_close(ni_socket_t *sock)
{
if (sock->close) {
sock->close(sock);
} else if (sock->__fd >= 0) {
close(sock->__fd);
if (sock->__fd >= 0) {
if (sock->close)
sock->close(sock);
else
close(sock->__fd);
sock->__fd = -1;
}
sock->__fd = -1;

ni_buffer_destroy(&sock->wbuf);
ni_buffer_destroy(&sock->rbuf);
Expand Down

0 comments on commit df32481

Please sign in to comment.