* [PATCH] libvhost-user: Handling potential memory allocation failures
@ 2022-11-08 8:01 jianchunfu
2022-11-08 8:54 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: jianchunfu @ 2022-11-08 8:01 UTC (permalink / raw)
To: qemu-trivial, qemu-devel; +Cc: mst, jianchunfu
Add malloc check of virtqueue element in libvhost-user.
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..901cd7a2c0 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__);
+ exit(0);
+ }
elem->out_num = out_num;
elem->in_num = in_num;
elem->in_sg = (void *)elem + in_sg_ofs;
--
2.18.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libvhost-user: Handling potential memory allocation failures
2022-11-08 8:01 [PATCH] libvhost-user: Handling potential memory allocation failures jianchunfu
@ 2022-11-08 8:54 ` Michael S. Tsirkin
2022-11-10 7:21 ` [RFC] libvhost-user: Add report when " jianchunfu
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2022-11-08 8:54 UTC (permalink / raw)
To: jianchunfu; +Cc: qemu-trivial, qemu-devel
On Tue, Nov 08, 2022 at 04:01:41PM +0800, jianchunfu wrote:
> Add malloc check of virtqueue element in libvhost-user.
>
> 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..901cd7a2c0 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__);
> + exit(0);
> + }
exit is certainly not the right way to handle such errors.
> elem->out_num = out_num;
> elem->in_num = in_num;
> elem->in_sg = (void *)elem + in_sg_ofs;
> --
> 2.18.4
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC] libvhost-user: Add report when allocation failures
2022-11-08 8:54 ` Michael S. Tsirkin
@ 2022-11-10 7:21 ` jianchunfu
0 siblings, 0 replies; 3+ messages in thread
From: jianchunfu @ 2022-11-10 7:21 UTC (permalink / raw)
To: mst; +Cc: qemu-devel, qemu-trivial, jianchunfu
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-10 7:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 8:01 [PATCH] libvhost-user: Handling potential memory allocation failures jianchunfu
2022-11-08 8:54 ` Michael S. Tsirkin
2022-11-10 7:21 ` [RFC] libvhost-user: Add report when " jianchunfu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).