diff mbox

virtio-scsi: Fix memory leak when realize failed

Message ID 1414669826-21550-1-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Oct. 30, 2014, 11:50 a.m. UTC
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 hw/scsi/virtio-scsi.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Max Reitz Nov. 3, 2014, 8:53 a.m. UTC | #1
On 2014-10-30 at 12:50, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>   hw/scsi/virtio-scsi.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index a1725b8..4aae1e8 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -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.

Reviewed-by: Max Reitz <mreitz@redhat.com>
Fam Zheng Nov. 3, 2014, 9:17 a.m. UTC | #2
On Mon, 11/03 09:53, Max Reitz wrote:
> On 2014-10-30 at 12:50, Fam Zheng wrote:
> >Signed-off-by: Fam Zheng <famz@redhat.com>
> >---
> >  hw/scsi/virtio-scsi.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> >diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> >index a1725b8..4aae1e8 100644
> >--- a/hw/scsi/virtio-scsi.c
> >+++ b/hw/scsi/virtio-scsi.c
> >@@ -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.
> 
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> 

Thanks, Paolo has sent a PULL req for this:

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

Fam
Max Reitz Nov. 3, 2014, 9:17 a.m. UTC | #3
On 2014-11-03 at 10:17, Fam Zheng wrote:
> On Mon, 11/03 09:53, Max Reitz wrote:
>> On 2014-10-30 at 12:50, Fam Zheng wrote:
>>> Signed-off-by: Fam Zheng <famz@redhat.com>
>>> ---
>>>   hw/scsi/virtio-scsi.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
>>> index a1725b8..4aae1e8 100644
>>> --- a/hw/scsi/virtio-scsi.c
>>> +++ b/hw/scsi/virtio-scsi.c
>>> @@ -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.
>>
>> Reviewed-by: Max Reitz <mreitz@redhat.com>
>>
> 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
diff mbox

Patch

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index a1725b8..4aae1e8 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -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 *));