diff options
-rw-r--r-- | blockdev-nbd.c | 4 | ||||
-rw-r--r-- | qemu-nbd.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 922cf5657b..b60b66d66c 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -27,8 +27,8 @@ static void nbd_accept(void *opaque) socklen_t addr_len = sizeof(addr); int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len); - if (fd >= 0) { - nbd_client_new(NULL, fd, nbd_client_put); + if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) { + close(fd); } } diff --git a/qemu-nbd.c b/qemu-nbd.c index eed79fa15e..f70e4b0dfc 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -369,8 +369,10 @@ static void nbd_accept(void *opaque) return; } - if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) { + if (nbd_client_new(exp, fd, nbd_client_closed)) { nb_fds++; + } else { + close(fd); } } |