提交 f1a0365b 编写于 作者: M Marc-André Lureau 提交者: Michael S. Tsirkin

vhost-net: always call vhost_dev_cleanup() on failure

vhost_dev_init(), calling vhost backend initialization, should be
cleaned up after failure too. Call vhost_dev_cleanup() in all failure
cases. First, it needs to zero-alloc the struct to avoid the initial
garbage.
Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 e0547b59
...@@ -140,7 +140,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) ...@@ -140,7 +140,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
{ {
int r; int r;
bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL; bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL;
struct vhost_net *net = g_malloc(sizeof *net); struct vhost_net *net = g_new0(struct vhost_net, 1);
uint64_t features = 0; uint64_t features = 0;
if (!options->net_backend) { if (!options->net_backend) {
...@@ -185,7 +185,6 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) ...@@ -185,7 +185,6 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
fprintf(stderr, "vhost lacks feature mask %" PRIu64 fprintf(stderr, "vhost lacks feature mask %" PRIu64
" for backend\n", " for backend\n",
(uint64_t)(~net->dev.features & net->dev.backend_features)); (uint64_t)(~net->dev.features & net->dev.backend_features));
vhost_dev_cleanup(&net->dev);
goto fail; goto fail;
} }
} }
...@@ -197,7 +196,6 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) ...@@ -197,7 +196,6 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
fprintf(stderr, "vhost lacks feature mask %" PRIu64 fprintf(stderr, "vhost lacks feature mask %" PRIu64
" for backend\n", " for backend\n",
(uint64_t)(~net->dev.features & features)); (uint64_t)(~net->dev.features & features));
vhost_dev_cleanup(&net->dev);
goto fail; goto fail;
} }
} }
...@@ -205,7 +203,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) ...@@ -205,7 +203,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
vhost_net_ack_features(net, features); vhost_net_ack_features(net, features);
return net; return net;
fail: fail:
vhost_dev_cleanup(&net->dev);
g_free(net); g_free(net);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册