[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 50/52] hw/scsi/vhost-scsi: don't leak vqs on error
From: |
Michael S. Tsirkin |
Subject: |
[PULL 50/52] hw/scsi/vhost-scsi: don't leak vqs on error |
Date: |
Thu, 6 Jan 2022 08:18:41 -0500 |
From: Daniil Tatianin <d-tatianin@yandex-team.ru>
vhost_dev_init calls vhost_dev_cleanup in case of an error during
initialization, which zeroes out the entire vsc->dev as well as the
vsc->dev.vqs pointer. This prevents us from properly freeing it in free_vqs.
Keep a local copy of the pointer so we can free it later.
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Message-Id: <20211129132358.1110372-1-d-tatianin@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/scsi/vhost-scsi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 039caf2614..efb3e14d9e 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -170,6 +170,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error
**errp)
Error *err = NULL;
int vhostfd = -1;
int ret;
+ struct vhost_virtqueue *vqs = NULL;
if (!vs->conf.wwpn) {
error_setg(errp, "vhost-scsi: missing wwpn");
@@ -213,7 +214,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error
**errp)
}
vsc->dev.nvqs = VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
- vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs);
+ vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs);
+ vsc->dev.vqs = vqs;
vsc->dev.vq_index = 0;
vsc->dev.backend_features = 0;
@@ -232,7 +234,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error
**errp)
return;
free_vqs:
- g_free(vsc->dev.vqs);
+ g_free(vqs);
if (!vsc->migratable) {
migrate_del_blocker(vsc->migration_blocker);
}
--
MST
- [PULL 41/52] virtio-mem: Set "unplugged-inaccessible=auto" for the 7.0 machine on x86, (continued)
- [PULL 41/52] virtio-mem: Set "unplugged-inaccessible=auto" for the 7.0 machine on x86, Michael S. Tsirkin, 2022/01/06
- [PULL 43/52] acpi: fix QEMU crash when started with SLIC table, Michael S. Tsirkin, 2022/01/06
- [PULL 42/52] intel-iommu: correctly check passthrough during translation, Michael S. Tsirkin, 2022/01/06
- [PULL 45/52] tests: acpi: add SLIC table test, Michael S. Tsirkin, 2022/01/06
- [PULL 47/52] acpihp: simplify acpi_pcihp_disable_root_bus, Michael S. Tsirkin, 2022/01/06
- [PULL 32/52] util/oslib-posix: Don't create too many threads with small memory or little pages, Michael S. Tsirkin, 2022/01/06
- [PULL 49/52] docs: reSTify virtio-balloon-stats documentation and move to docs/interop, Michael S. Tsirkin, 2022/01/06
- [PULL 38/52] MAINTAINERS: Add a separate entry for acpi/VIOT tables, Michael S. Tsirkin, 2022/01/06
- [PULL 30/52] util/oslib-posix: Support MADV_POPULATE_WRITE for os_mem_prealloc(), Michael S. Tsirkin, 2022/01/06
- [PULL 48/52] hw/i386/pc: Add missing property descriptions, Michael S. Tsirkin, 2022/01/06
- [PULL 50/52] hw/scsi/vhost-scsi: don't leak vqs on error,
Michael S. Tsirkin <=
- [PULL 51/52] hw/scsi/vhost-scsi: don't double close vhostfd on error, Michael S. Tsirkin, 2022/01/06
- [PULL 52/52] virtio/vhost-vsock: don't double close vhostfd, remove redundant cleanup, Michael S. Tsirkin, 2022/01/06
- [PULL 44/52] tests: acpi: whitelist expected blobs before changing them, Michael S. Tsirkin, 2022/01/06
- [PULL 04/52] virtio-pci: decouple notifier from interrupt process, Michael S. Tsirkin, 2022/01/06
- Re: [PULL 00/52] virtio,pci,pc: features,fixes,cleanups, Richard Henderson, 2022/01/06