[RFC] libvhost-user: Add report when allocation failures

jianchunfu posted 1 patch 1 year, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20221110072157.4242-1-jianchunfu@cmss.chinamobile.com
subprojects/libvhost-user/libvhost-user.c | 4 ++++
1 file changed, 4 insertions(+)
[RFC] libvhost-user: Add report when allocation failures
Posted by jianchunfu 1 year, 6 months ago
Add error report when malloc fails of virtqueue element.
It's a little pointless to return NULL, wouldn't it be right
to report error and exit when malloc fails since it is in a
standalone project while not QEMU.

Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
 subprojects/libvhost-user/libvhost-user.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index 47d2efc60f..c2bdf0fcc1 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -2551,6 +2551,10 @@ virtqueue_alloc_element(size_t sz,
 
     assert(sz >= sizeof(VuVirtqElement));
     elem = malloc(out_sg_end);
+    if (!elem) {
+        DPRINT("%s: failed to malloc virtqelement\n", __func__);
+        return NULL;
+    }
     elem->out_num = out_num;
     elem->in_num = in_num;
     elem->in_sg = (void *)elem + in_sg_ofs;
-- 
2.18.4