From 1e9057a97b3d5045f17412f19a9dc578a8067cc9 Mon Sep 17 00:00:00 2001 From: Jianfeng Tan Date: Thu, 26 Jan 2017 03:05:42 +0000 Subject: [PATCH] net/virtio-user: check value returned from malloc Value returned from malloc is not checked for errors before being used. This patch fixes following coverity issue. static struct vhost_memory_kernel * prepare_vhost_memory_kernel(void) { ... vm = malloc(sizeof(struct vhost_memory_kernel) + max_regions * sizeof(struct vhost_memory_region)); ... >>> CID 140744: (NULL_RETURNS) >>> Dereferencing a null pointer "vm". mr = &vm->regions[k++]; Coverity issue: 140744 Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost") Signed-off-by: Jianfeng Tan Acked-by: Yuanhan Liu --- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index 9b6637d6a2..05aa6c6d5c 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -114,6 +114,8 @@ prepare_vhost_memory_kernel(void) vm = malloc(sizeof(struct vhost_memory_kernel) + max_regions * sizeof(struct vhost_memory_region)); + if (!vm) + return NULL; for (i = 0; i < RTE_MAX_MEMSEG; ++i) { seg = &rte_eal_get_configuration()->mem_config->memseg[i]; -- 2.20.1