Commit 8d7e75be authored by Zhiqiang Liu's avatar Zhiqiang Liu Committed by Tomasz Zawadzki
Browse files

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: default avatarZhiqiang 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: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarsunshihao <sunshihao@huawei.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 14ad24c7
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1708,6 +1708,7 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport,
	}
	free(path);

	endpoint->fd = fd;
	err = ftruncate(fd, NVMF_VFIO_USER_DOORBELLS_OFFSET + NVMF_VFIO_USER_DOORBELLS_SIZE);
	if (err != 0) {
		goto out;
@@ -1721,8 +1722,6 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport,
		goto out;
	}

	endpoint->fd = fd;

	snprintf(uuid, PATH_MAX, "%s/cntrl", endpoint_id(endpoint));

	endpoint->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, uuid, LIBVFIO_USER_FLAG_ATTACH_NB,