From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jens Freimann Subject: [PATCH] vhost: check malloc return value when allocating guest pages Date: Thu, 11 May 2017 17:25:26 +0200 Message-ID: <20170511152526.18379-1-jfreimann@redhat.com> Cc: yuanhan.liu@linux.intel.com, maxime.coquelin@redhat.com To: dev@dpdk.org Return-path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id DA2DC282 for ; Thu, 11 May 2017 17:25:31 +0200 (CEST) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When we try to allocate guest pages we need to check the return value of malloc(). Print an error message and return when it fails. Signed-off-by: Jens Freimann --- lib/librte_vhost/vhost_user.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 5c8058b..437e41f 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -515,6 +515,13 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) dev->max_guest_pages = 8; dev->guest_pages = malloc(dev->max_guest_pages * sizeof(struct guest_page)); + if (dev->guest_pages == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, + "(%d) failed to allocate memory " + "for dev->guest_pages\n", + dev->vid); + return -1; + } } dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) + -- 2.9.3