diff mbox series

[v4,2/2] virtio-iommu: avoid memleak in the unrealize

Message ID 20200328005705.29898-3-pannengyuan@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix two virtio queues memleak | expand

Commit Message

Pan Nengyuan March 28, 2020, 12:57 a.m. UTC
req_vq/event_vq forgot to free in unrealize. Fix that.
And also do clean 's->as_by_busptr' hash table in unrealize to fix another leak.

Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Acked-by: Eric Auger <eric.auger@redhat.com>
---
Cc: Eric Auger <eric.auger@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
---
v3->v1/v2:
- Also clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
v4->v3:
- update subject msg and move g_hash_table_destroy to the beginning of unrealize.
---
 hw/virtio/virtio-iommu.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Stefano Garzarella March 30, 2020, 7:24 a.m. UTC | #1
On Sat, Mar 28, 2020 at 08:57:05AM +0800, Pan Nengyuan wrote:
> req_vq/event_vq forgot to free in unrealize. Fix that.
> And also do clean 's->as_by_busptr' hash table in unrealize to fix another leak.
> 
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Acked-by: Eric Auger <eric.auger@redhat.com>
> ---
> Cc: Eric Auger <eric.auger@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> v3->v1/v2:
> - Also clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
> v4->v3:
> - update subject msg and move g_hash_table_destroy to the beginning of unrealize.
> ---
>  hw/virtio/virtio-iommu.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Thanks,
Stefano

> 
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 4cee8083bc..22ba8848c2 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -693,9 +693,12 @@ static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
>  
> +    g_hash_table_destroy(s->as_by_busptr);
>      g_tree_destroy(s->domains);
>      g_tree_destroy(s->endpoints);
>  
> +    virtio_delete_queue(s->req_vq);
> +    virtio_delete_queue(s->event_vq);
>      virtio_cleanup(vdev);
>  }
>  
> -- 
> 2.18.2
> 
>
diff mbox series

Patch

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 4cee8083bc..22ba8848c2 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -693,9 +693,12 @@  static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
 
+    g_hash_table_destroy(s->as_by_busptr);
     g_tree_destroy(s->domains);
     g_tree_destroy(s->endpoints);
 
+    virtio_delete_queue(s->req_vq);
+    virtio_delete_queue(s->event_vq);
     virtio_cleanup(vdev);
 }