aboutsummaryrefslogtreecommitdiff
path: root/nbd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nbd.c')
-rw-r--r--nbd.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/nbd.c b/nbd.c
index b3d9654499..f8d0221da1 100644
--- a/nbd.c
+++ b/nbd.c
@@ -1475,8 +1475,7 @@ static void nbd_update_can_read(NBDClient *client)
}
}
-NBDClient *nbd_client_new(NBDExport *exp, int csock,
- void (*close)(NBDClient *))
+void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *))
{
NBDClient *client;
client = g_malloc0(sizeof(NBDClient));
@@ -1485,10 +1484,11 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
client->sock = csock;
client->can_read = true;
if (nbd_send_negotiate(client)) {
- g_free(client);
- return NULL;
+ shutdown(client->sock, 2);
+ close_fn(client);
+ return;
}
- client->close = close;
+ client->close = close_fn;
qemu_co_mutex_init(&client->send_lock);
nbd_set_handlers(client);
@@ -1496,5 +1496,4 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
QTAILQ_INSERT_TAIL(&exp->clients, client, next);
nbd_export_get(exp);
}
- return client;
}