Skip to content

Commit

Permalink
vhost-user-scsi: Call virtio_scsi_common_unrealize() when device real…
Browse files Browse the repository at this point in the history
…ize failed

This avoids memory leak when device hotplug is failed.

Signed-off-by: Xie Yongji <xieyongji@baidu.com>
Message-Id: <20190717004606.12444-2-xieyongji@baidu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Xie Yongji authored and bonzini committed Jul 19, 2019
1 parent 934443c commit 68fa7ca
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions hw/scsi/vhost-user-scsi.c
Expand Up @@ -87,7 +87,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
}

if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) {
return;
goto free_virtio;
}

vsc->dev.nvqs = 2 + vs->conf.num_queues;
Expand All @@ -101,15 +101,21 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
if (ret < 0) {
error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s",
strerror(-ret));
vhost_user_cleanup(&s->vhost_user);
g_free(vqs);
return;
goto free_vhost;
}

/* Channel and lun both are 0 for bootable vhost-user-scsi disk */
vsc->channel = 0;
vsc->lun = 0;
vsc->target = vs->conf.boot_tpgt;

return;

free_vhost:
vhost_user_cleanup(&s->vhost_user);
g_free(vqs);
free_virtio:
virtio_scsi_common_unrealize(dev);
}

static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)
Expand Down

0 comments on commit 68fa7ca

Please sign in to comment.