diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 31c9d34637..6a6c15dd32 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -93,7 +93,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) } vsc->dev.nvqs = 2 + vs->conf.num_queues; - vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs); + vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index = 0; vsc->dev.backend_features = 0; vqs = vsc->dev.vqs; diff --git a/util/async.c b/util/async.c index 8d2105729c..4e4c7af51e 100644 --- a/util/async.c +++ b/util/async.c @@ -459,9 +459,17 @@ void aio_co_schedule(AioContext *ctx, Coroutine *co) abort(); } + /* The coroutine might run and release the last ctx reference before we + * invoke qemu_bh_schedule(). Take a reference to keep ctx alive until + * we're done. + */ + aio_context_ref(ctx); + QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines, co, co_scheduled_next); qemu_bh_schedule(ctx->co_schedule_bh); + + aio_context_unref(ctx); } void aio_co_wake(struct Coroutine *co)