summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorhust202013232 <[email protected]>2023-05-12 13:37:42 +0800
committerGitHub <[email protected]>2023-05-12 01:37:42 -0400
commit9dd0d4125190907332c0510a1449c3cfdb0104bf (patch)
tree4bdcf1d26e59c9c4cd8fb86102ee46241d186181 /components
parent22a7bf8711941f4796878c0699e22676b570e628 (diff)
[components][rndis.c] add safety checking after allocating memory
Diffstat (limited to 'components')
-rw-r--r--components/drivers/usb/usbdevice/class/rndis.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/components/drivers/usb/usbdevice/class/rndis.c b/components/drivers/usb/usbdevice/class/rndis.c
index 1fe48c7e9d..d3ea89ee0a 100644
--- a/components/drivers/usb/usbdevice/class/rndis.c
+++ b/components/drivers/usb/usbdevice/class/rndis.c
@@ -1348,6 +1348,19 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device)
intf_comm = rt_usbd_interface_new(device, _interface_handler);
intf_data = rt_usbd_interface_new(device, _interface_handler);
+ if((intf_comm == RT_NULL) || (intf_data == RT_NULL))
+ {
+ LOG_E("%s,%d: no memory!", __func__, __LINE__);
+
+ if(intf_comm != RT_NULL)
+ rt_free(intf_comm);
+
+ if(intf_data != RT_NULL)
+ rt_free(intf_data);
+
+ return RT_NULL;
+ }
+
/* create a communication alternate setting and a data alternate setting */
comm_setting = rt_usbd_altsetting_new(sizeof(struct ucdc_comm_descriptor));
data_setting = rt_usbd_altsetting_new(sizeof(struct ucdc_data_descriptor));