Skip to contentSkip to conversation

virtio-scsi: Fix memory leak when realize failed

PATCH In review Fam Zheng 2 participants 4 messages Oct 31, 2014 – Nov 3, 2014

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 virtio-scsi: Fix memory leak when realize failed

---
 hw/scsi/virtio-scsi.c | 1 +
 1 file changed, 1 insertion(+)
hw/scsi/virtio-scsi.c +1 -0
index a1725b8..4aae1e8 100644
@@ -793,6 +793,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
         error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
                          "must be a positive integer less than %d.",
                    s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+        virtio_cleanup(vdev);
         return;
     }
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Fam Zheng
---
  hw/scsi/virtio-scsi.c | 1 +
  1 file changed, 1 insertion(+)
hw/scsi/virtio-scsi.c +0 -0
index a1725b8..4aae1e8 100644

hw/scsi/virtio-scsi.c void virtio_scsi_common_realize(DeviceState *dev, Error **errp, · line 799

Quoted 7 lines
hw/scsi/virtio-scsi.c +1 -0
@@ -793,6 +793,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
          error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
                           "must be a positive integer less than %d.",
                     s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+        virtio_cleanup(vdev);
          return;
      }
      s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));

The alternative would be to simply push virtio_init() below this check, but it's fine either way.

author
#2 lore raw
Quoted 22 lines · Max Reitz
Quoted 10 lines · Fam Zheng
---
 hw/scsi/virtio-scsi.c | 1 +
 1 file changed, 1 insertion(+)
hw/scsi/virtio-scsi.c +0 -0
index a1725b8..4aae1e8 100644

hw/scsi/virtio-scsi.c void virtio_scsi_common_realize(DeviceState *dev, Error **errp, · line 799

Quoted 7 lines
hw/scsi/virtio-scsi.c +1 -0
@@ -793,6 +793,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
         error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
                          "must be a positive integer less than %d.",
                    s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+        virtio_cleanup(vdev);
         return;
     }
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));

The alternative would be to simply push virtio_init() below this check, but it's fine either way.

Quoted 2 lines

Thanks, Paolo has sent a PULL req for this:

http://lists.gnu.org/archive/html/qemu-devel/2014-10/msg04113.html

Fam

#3 lore raw
Quoted 22 lines · Fam Zheng
Quoted 21 lines · Max Reitz
Quoted 10 lines · Fam Zheng
---
  hw/scsi/virtio-scsi.c | 1 +
  1 file changed, 1 insertion(+)
hw/scsi/virtio-scsi.c +0 -0
index a1725b8..4aae1e8 100644

hw/scsi/virtio-scsi.c void virtio_scsi_common_realize(DeviceState *dev, Error **errp, · line 799

Quoted 7 lines
hw/scsi/virtio-scsi.c +1 -0
@@ -793,6 +793,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
          error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
                           "must be a positive integer less than %d.",
                     s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+        virtio_cleanup(vdev);
          return;
      }
      s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));

The alternative would be to simply push virtio_init() below this check, but it's fine either way.

Quoted 7 lines
Quoted 2 lines

Thanks, Paolo has sent a PULL req for this:

http://lists.gnu.org/archive/html/qemu-devel/2014-10/msg04113.html

Fam

Ah, okay. :-)

Max