[PATCH 1/2] virtio-iommu: Check gtrees are non null before destroying them

Eric Auger posted 2 patches 5 years, 5 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Eric Auger <eric.auger@redhat.com>
There is a newer version of this series
[PATCH 1/2] virtio-iommu: Check gtrees are non null before destroying them
Posted by Eric Auger 5 years, 5 months ago
If realize fails, domains and endpoints trees may be NULL. On
unrealize(), this produces asseryions:
 "GLib: g_tree_destroy: assertion 'tree != NULL' failed"

Check the tree are non NULL before destroying them.

Cc: qemu-stable@nongnu.org
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 hw/virtio/virtio-iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 5d56865e56..21ec63b108 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -801,8 +801,12 @@ static void virtio_iommu_device_unrealize(DeviceState *dev)
     VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
 
     g_hash_table_destroy(s->as_by_busptr);
-    g_tree_destroy(s->domains);
-    g_tree_destroy(s->endpoints);
+    if (s->domains) {
+        g_tree_destroy(s->domains);
+    }
+    if (s->endpoints) {
+        g_tree_destroy(s->endpoints);
+    }
 
     virtio_delete_queue(s->req_vq);
     virtio_delete_queue(s->event_vq);
-- 
2.21.3


Re: [PATCH 1/2] virtio-iommu: Check gtrees are non null before destroying them
Posted by Cornelia Huck 5 years, 5 months ago
On Wed,  2 Sep 2020 15:11:51 +0200
Eric Auger <eric.auger@redhat.com> wrote:

> If realize fails, domains and endpoints trees may be NULL. On
> unrealize(), this produces asseryions:

s/asseryions/assertions/

>  "GLib: g_tree_destroy: assertion 'tree != NULL' failed"
> 
> Check the tree are non NULL before destroying them.

s/the tree/that the trees/

> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> ---
>  hw/virtio/virtio-iommu.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Good to see that the version checking has flushed out a bug :)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>