]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
vhost-user-base: free virtqueue array during cleanup
authorGuoHan Zhao <zhaoguohan@kylinos.cn>
Mon, 29 Jun 2026 09:26:18 +0000 (17:26 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Sat, 4 Jul 2026 09:03:47 +0000 (05:03 -0400)
vhost-user-base stores the VirtQueue pointers in a GPtrArray, but its
cleanup helper only deletes the VirtQueues and leaves the array itself
allocated.

Free the GPtrArray after deleting the queues and clear the pointer so
cleanup remains safe if the error path reaches it with no queues to
release.

Fixes: 6275989647ef (virtio: split into vhost-user-base and vhost-user-device)
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260629092619.2607275-1-zhaoguohan@kylinos.cn>

hw/virtio/vhost-user-base.c

index 39b5e637fc37694e3bb627bcca14a1e9ade6f624..6ac523f9ebef820e5fd94fbe1bb68fa0a28169fa 100644 (file)
@@ -193,9 +193,13 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserBase *vub)
 {
     vhost_user_cleanup(&vub->vhost_user);
 
-    for (int i = 0; i < vub->num_vqs; i++) {
-        VirtQueue *vq = g_ptr_array_index(vub->vqs, i);
-        virtio_delete_queue(vq);
+    if (vub->vqs) {
+        for (int i = 0; i < vub->num_vqs; i++) {
+            VirtQueue *vq = g_ptr_array_index(vub->vqs, i);
+            virtio_delete_queue(vq);
+        }
+        g_ptr_array_free(vub->vqs, true);
+        vub->vqs = NULL;
     }
 
     virtio_cleanup(vdev);