aboutsummaryrefslogtreecommitdiff
path: root/lib/tran_sock.c
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-03-22 16:58:14 +0000
committerGitHub <noreply@github.com>2021-03-22 16:58:14 +0000
commit8ba55dfb9bb54b773513e78d87d9ebe078384573 (patch)
tree271dd06dec57e1d0702251db1d6cc05fea27006b /lib/tran_sock.c
parent3c33c863a178dbb656c835a000df0defdbaa1a9d (diff)
downloadlibvfio-user-8ba55dfb9bb54b773513e78d87d9ebe078384573.zip
libvfio-user-8ba55dfb9bb54b773513e78d87d9ebe078384573.tar.gz
libvfio-user-8ba55dfb9bb54b773513e78d87d9ebe078384573.tar.bz2
fix vfu_ctx_create() error path (#393)
The ->detach() and ->fini() transport handlers can't presume ->tran_data is set, since we cleanup a failed vfu_create_ctx() with vfu_destroy_ctx(). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'lib/tran_sock.c')
-rw-r--r--lib/tran_sock.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index 51a8566..87072d6 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -848,11 +848,10 @@ tran_sock_detach(vfu_ctx_t *vfu_ctx)
tran_sock_t *ts;
assert(vfu_ctx != NULL);
- assert(vfu_ctx->tran_data != NULL);
ts = vfu_ctx->tran_data;
- if (ts->conn_fd != -1) {
+ if (ts != NULL && ts->conn_fd != -1) {
// FIXME: handle EINTR
(void) close(ts->conn_fd);
ts->conn_fd = -1;
@@ -865,11 +864,10 @@ tran_sock_fini(vfu_ctx_t *vfu_ctx)
tran_sock_t *ts;
assert(vfu_ctx != NULL);
- assert(vfu_ctx->tran_data != NULL);
ts = vfu_ctx->tran_data;
- if (ts->listen_fd != -1) {
+ if (ts != NULL && ts->listen_fd != -1) {
// FIXME: handle EINTR
(void) close(ts->listen_fd);
ts->listen_fd = -1;