diff mbox series

[v3,2/2] virtio-iommu: delete vqs in unrealize to fix memleak

Message ID 20200327095642.18424-3-pannengyuan@huawei.com
State New
Headers show
Series fix two virtio queues memleak | expand

Commit Message

Pan Nengyuan March 27, 2020, 9:56 a.m. UTC
req_vq/event_vq forgot to free in unrealize. Fix that.
And aslo 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>
---
v3->v1/v2:
- Aslo clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
---
 hw/virtio/virtio-iommu.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Stefano Garzarella March 27, 2020, 4:26 p.m. UTC | #1
On Fri, Mar 27, 2020 at 05:56:42PM +0800, Pan Nengyuan wrote:
> req_vq/event_vq forgot to free in unrealize. Fix that.
> And aslo do clean 's->as_by_busptr' hash table in unrealize to fix another leak.

s/aslo/also

Maybe we can also update the subject in something like this:
"virtio-iommu: avoid memleak in the unrealize"

> 
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Acked-by: Eric Auger <eric.auger@redhat.com>
> ---
> Cc: Eric Auger <eric.auger@redhat.com>
> ---
> v3->v1/v2:
> - Aslo clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
> ---
>  hw/virtio/virtio-iommu.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 4cee8083bc..694698fa0f 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -696,7 +696,10 @@ static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
>      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);
> +    g_hash_table_destroy(s->as_by_busptr);

If you need to respin, you could move g_hash_table_destroy()
at the beggining of unrealize(), just to follow a reverse order of
realize().

Thanks,
Stefano

>  }
>  
>  static void virtio_iommu_device_reset(VirtIODevice *vdev)
> -- 
> 2.18.2
> 
>
Pan Nengyuan March 28, 2020, 12:31 a.m. UTC | #2
On 3/28/2020 12:26 AM, Stefano Garzarella wrote:
> On Fri, Mar 27, 2020 at 05:56:42PM +0800, Pan Nengyuan wrote:
>> req_vq/event_vq forgot to free in unrealize. Fix that.
>> And aslo do clean 's->as_by_busptr' hash table in unrealize to fix another leak.
> 
> s/aslo/also
> 
> Maybe we can also update the subject in something like this:
> "virtio-iommu: avoid memleak in the unrealize"

OK.

> 
>>
>> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
>> Acked-by: Eric Auger <eric.auger@redhat.com>
>> ---
>> Cc: Eric Auger <eric.auger@redhat.com>
>> ---
>> v3->v1/v2:
>> - Aslo clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
>> ---
>>  hw/virtio/virtio-iommu.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
>> index 4cee8083bc..694698fa0f 100644
>> --- a/hw/virtio/virtio-iommu.c
>> +++ b/hw/virtio/virtio-iommu.c
>> @@ -696,7 +696,10 @@ static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
>>      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);
>> +    g_hash_table_destroy(s->as_by_busptr);
> 
> If you need to respin, you could move g_hash_table_destroy()
> at the beggining of unrealize(), just to follow a reverse order of
> realize().

OK.

Thanks.

> 
> Thanks,
> Stefano
> 
>>  }
>>  
>>  static void virtio_iommu_device_reset(VirtIODevice *vdev)
>> -- 
>> 2.18.2
>>
>>
>
diff mbox series

Patch

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 4cee8083bc..694698fa0f 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -696,7 +696,10 @@  static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
     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);
+    g_hash_table_destroy(s->as_by_busptr);
 }
 
 static void virtio_iommu_device_reset(VirtIODevice *vdev)