summary refs log tree commit diff stats
path: root/hw/scsi/vhost-user-scsi.c
diff options
context:
space:
mode:
authorXie Yongji <xieyongji@baidu.com>2019-07-17 08:46:06 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2019-07-19 19:04:49 +0200
commit68fa7ca015dc8afb86e3aa51b31362f63048bd5c (patch)
treef402d2cf5db730a0732edf945aa797726b6fc314 /hw/scsi/vhost-user-scsi.c
parent934443c37befc9e268f5c661cb9552a2ee572e19 (diff)
downloadfocaccia-qemu-68fa7ca015dc8afb86e3aa51b31362f63048bd5c.tar.gz
focaccia-qemu-68fa7ca015dc8afb86e3aa51b31362f63048bd5c.zip
vhost-user-scsi: Call virtio_scsi_common_unrealize() when device realize 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>
Diffstat (limited to 'hw/scsi/vhost-user-scsi.c')
-rw-r--r--hw/scsi/vhost-user-scsi.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index a0b69fbc0f..fcee67d5a7 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -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;
@@ -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)