@samitouri / QOSamiQemu / commits / ed963d3967

vhost-user-base: free virtqueue array during cleanup

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>

GuoHan Zhao committed Jun 29, 2026 at 17:26 UTC ed963d3967fd8e5ca551c1cc6fcbabaef010d72e
1 file changed +7 -3
hw/virtio/vhost-user-base.c
+7 -3
@@ -193,9 +193,13 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserBase *vub)
193 {
194 vhost_user_cleanup(&vub->vhost_user);
195
196 - for (int i = 0; i < vub->num_vqs; i++) {
197 - VirtQueue *vq = g_ptr_array_index(vub->vqs, i);
198 - virtio_delete_queue(vq);
196 + if (vub->vqs) {
197 + for (int i = 0; i < vub->num_vqs; i++) {
198 + VirtQueue *vq = g_ptr_array_index(vub->vqs, i);
199 + virtio_delete_queue(vq);
200 + }
201 + g_ptr_array_free(vub->vqs, true);
202 + vub->vqs = NULL;
203 }
204
205 virtio_cleanup(vdev);