nvmf: fix fd leakage problem in nvmf_vfio_user_listen()

In nvmf_vfio_user_listen(), fd should be closed before
set it to endpoint->fd, otherwise, the fd leakage probem
occurs.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Change-Id: I3fabc65d2764926e5873475962e4362e46eb37e4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8309
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: sunshihao <sunshihao@huawei.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Zhiqiang Liu 2021-06-13 20:12:17 +08:00 committed by Tomasz Zawadzki
parent 14ad24c7b8
commit 8d7e75be24

View File

@ -1708,6 +1708,7 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport,
} }
free(path); free(path);
endpoint->fd = fd;
err = ftruncate(fd, NVMF_VFIO_USER_DOORBELLS_OFFSET + NVMF_VFIO_USER_DOORBELLS_SIZE); err = ftruncate(fd, NVMF_VFIO_USER_DOORBELLS_OFFSET + NVMF_VFIO_USER_DOORBELLS_SIZE);
if (err != 0) { if (err != 0) {
goto out; goto out;
@ -1721,8 +1722,6 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport,
goto out; goto out;
} }
endpoint->fd = fd;
snprintf(uuid, PATH_MAX, "%s/cntrl", endpoint_id(endpoint)); snprintf(uuid, PATH_MAX, "%s/cntrl", endpoint_id(endpoint));
endpoint->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, uuid, LIBVFIO_USER_FLAG_ATTACH_NB, endpoint->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, uuid, LIBVFIO_USER_FLAG_ATTACH_NB,