diff mbox series

[v2,1/2] vhost-scsi: Call virtio_scsi_common_unrealize() when device realize failed

Message ID 20190717004606.12444-1-xieyongji@baidu.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] vhost-scsi: Call virtio_scsi_common_unrealize() when device realize failed | expand

Commit Message

Yongji Xie July 17, 2019, 12:46 a.m. UTC
From: Xie Yongji <xieyongji@baidu.com>

This avoids memory leak when device hotplug is failed.

Signed-off-by: Xie Yongji <xieyongji@baidu.com>
---
 hw/scsi/vhost-scsi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 4090f99ee4..c0dd9bdf89 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -210,7 +210,7 @@  static void vhost_scsi_realize(DeviceState *dev, Error **errp)
         if (err) {
             error_propagate(errp, err);
             error_free(vsc->migration_blocker);
-            goto close_fd;
+            goto free_virtio;
         }
     }
 
@@ -240,6 +240,10 @@  static void vhost_scsi_realize(DeviceState *dev, Error **errp)
         migrate_del_blocker(vsc->migration_blocker);
     }
     g_free(vsc->dev.vqs);
+ free_virtio:
+    err = NULL;
+    virtio_scsi_common_unrealize(dev, &err);
+    error_propagate(errp, err);
  close_fd:
     close(vhostfd);
     return;