From: Andrey Drobyshev <[email protected]> In vhost_vsock_device_realize(), after unsuccessful call to qemu_set_blocking(vhostfd, false), vhostfd gets leaked. Let's close it explicitly in this case. CPR-saved FDs don't get automatically closed, thus it is safe both for vhostfd obtained from cpr_find_fd() and from open(/dev/vhost-vsock).
Signed-off-by: Andrey Drobyshev <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Message-ID: <[email protected]> --- hw/virtio/vhost-vsock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index c582ac9fcc..3ec20d8760 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -176,20 +176,17 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) error_prepend(errp, "vhost-vsock: unable to parse vhostfd: "); goto err_blocker; } - - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto err_blocker; - } } else { vhostfd = open("/dev/vhost-vsock", O_RDWR); if (vhostfd < 0) { error_setg_file_open(errp, errno, "/dev/vhost-vsock"); goto err_blocker; } + } - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto err_blocker; - } + if (!qemu_set_blocking(vhostfd, false, errp)) { + close(vhostfd); + goto err_blocker; } vhost_vsock_common_realize(vdev); -- MST
