nbd: Close socket on negotiation failure.
authorHani Benhabiles <kroosec@gmail.com>
Mon, 12 May 2014 23:35:15 +0000 (00:35 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Fri, 23 May 2014 20:07:29 +0000 (00:07 +0400)
Otherwise, the nbd client may hang waiting for the server response.

Signed-off-by: Hani Benhabiles <hani@linux.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
blockdev-nbd.c
qemu-nbd.c

index 922cf5657b99f23f4a8afc707c0e0bf79d03bbd0..b60b66d66c2bbe7eaea66abd7a3f3d27e638c82b 100644 (file)
@@ -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);
     }
 }
 
index eed79fa15e78ef59f06b4331f82b44b770ef941d..f70e4b0dfc4edfd3502a9978a7667f91437eaa93 100644 (file)
@@ -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);
     }
 }