Message ID | 20221108080141.5756-1-jianchunfu@cmss.chinamobile.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | libvhost-user: Handling potential memory allocation failures | expand |
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 > >
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;
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(+)