From 4cee38a6fca1f9d8ea67811090166de4393b0518 Mon Sep 17 00:00:00 2001 From: Jens Freimann Date: Thu, 11 May 2017 17:25:26 +0200 Subject: [PATCH] vhost: check allocation of guest pages 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 Reviewed-by: Maxime Coquelin Acked-by: Yuanhan Liu --- 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 5c8058b62c..437e41f8be 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.20.1