From 8f464f0f52ac4c10b1c10376d26eddc644492966 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 4 Feb 2021 09:58:55 +0000 Subject: close listening socket in vfu_destroy_ctx() (#299) We were forgetting to close vfu_ctx->fd, add a tran callback for this. While we're there, clean up the tran callbacks somewhat. Signed-off-by: John Levon Reviewed-by: Swapnil Ingle --- lib/libvfio-user.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/libvfio-user.c') diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 83fb9a5..fce7923 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -1088,6 +1088,11 @@ vfu_destroy_ctx(vfu_ctx_t *vfu_ctx) if (vfu_ctx->trans->detach != NULL) { vfu_ctx->trans->detach(vfu_ctx); } + + if (vfu_ctx->trans->fini != NULL) { + vfu_ctx->trans->fini(vfu_ctx); + } + if (vfu_ctx->dma != NULL) { dma_controller_destroy(vfu_ctx->dma); } @@ -1123,6 +1128,8 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt, vfu_ctx_t *vfu_ctx = NULL; int err = 0; + //FIXME: Validate arguments. + if (trans != VFU_TRANS_SOCK) { errno = ENOTSUP; return NULL; @@ -1138,11 +1145,11 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt, errno = ENOMEM; return NULL; } + + vfu_ctx->fd = -1; + vfu_ctx->conn_fd = -1; vfu_ctx->dev_type = dev_type; vfu_ctx->trans = &sock_transport_ops; - - //FIXME: Validate arguments. - // Set other context data. vfu_ctx->pvt = pvt; vfu_ctx->flags = flags; vfu_ctx->log_level = LOG_ERR; -- cgit v1.1