All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] vhost-user-base: free virtqueue array during cleanup
@ 2026-06-29  9:26 zhaoguohan
  2026-06-29  9:26 ` [PATCH 2/2] vhost-user-base: clean up vhost_dev on realize failure zhaoguohan
  0 siblings, 1 reply; 4+ messages in thread
From: zhaoguohan @ 2026-06-29  9:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, Michael S. Tsirkin, Stefano Garzarella

From: GuoHan Zhao <zhaoguohan@kylinos.cn>

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>
---
 hw/virtio/vhost-user-base.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c
index 39b5e637fc37..6ac523f9ebef 100644
--- a/hw/virtio/vhost-user-base.c
+++ b/hw/virtio/vhost-user-base.c
@@ -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);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-30  1:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29  9:26 [PATCH 1/2] vhost-user-base: free virtqueue array during cleanup zhaoguohan
2026-06-29  9:26 ` [PATCH 2/2] vhost-user-base: clean up vhost_dev on realize failure zhaoguohan
2026-06-29  9:57   ` Michael S. Tsirkin
2026-06-30  1:20   ` [PATCH v2 " zhaoguohan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.