vhost: Fix vhostfd leak in error branch
authorGonglei <arei.gonglei@huawei.com>
Fri, 28 Nov 2014 09:26:29 +0000 (17:26 +0800)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 1 Dec 2014 12:29:35 +0000 (12:29 +0000)
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-id: 1417166789-1960-1-git-send-email-arei.gonglei@huawei.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/scsi/vhost-scsi.c
hw/virtio/vhost.c

index 308b393..dcb2bc5 100644 (file)
@@ -233,6 +233,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
                                vhost_dummy_handle_output);
     if (err != NULL) {
         error_propagate(errp, err);
+        close(vhostfd);
         return;
     }
 
index 5d7c40a..5a12861 100644 (file)
@@ -817,10 +817,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
     int i, r;
 
     if (vhost_set_backend_type(hdev, backend_type) < 0) {
+        close((uintptr_t)opaque);
         return -1;
     }
 
     if (hdev->vhost_ops->vhost_backend_init(hdev, opaque) < 0) {
+        close((uintptr_t)opaque);
         return -errno;
     }