From: Yuanhan Liu Date: Tue, 28 Jun 2016 03:58:31 +0000 (+0800) Subject: vhost: fix potential null pointer dereference X-Git-Tag: spdx-start~6229 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=9d8365874e37ca118dab03bf63ec7400b33d5948;p=dpdk.git vhost: fix potential null pointer dereference Fix the potential NULL pointer dereference issue raised by Coverity. 578 reconn = malloc(sizeof(*reconn)); >>> CID 127481: Null pointer dereferences (NULL_RETURNS) >>> Dereferencing a null pointer "reconn". 579 reconn->un = un; Coverity issue: 127481 Fixes: e623e0c6d8a5 ("vhost: add reconnect ability") Reported-by: John McNamara Signed-off-by: Yuanhan Liu --- diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c index 67303a43a8..a0d83f3c97 100644 --- a/lib/librte_vhost/vhost_user/vhost-net-user.c +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c @@ -577,6 +577,12 @@ vhost_user_create_client(struct vhost_user_socket *vsocket) RTE_LOG(ERR, VHOST_CONFIG, "%s: reconnecting...\n", path); reconn = malloc(sizeof(*reconn)); + if (reconn == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, + "failed to allocate memory for reconnect\n"); + close(fd); + return -1; + } reconn->un = un; reconn->fd = fd; reconn->vsocket = vsocket;