[winusb.c] add checking after allocating memory for variable winusb_device to make sure allocae is successful

This commit is contained in:
ourea1429 2023-04-28 21:59:42 +08:00 committed by GitHub
parent a8b7e28741
commit 085ded8eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -324,6 +324,8 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device)
/* allocate memory for cdc vcom data */
winusb_device = (winusb_device_t)rt_malloc(sizeof(struct winusb_device));
if (winusb_device == NULL)
return RT_NULL;
rt_memset((void *)winusb_device, 0, sizeof(struct winusb_device));
func->user_data = (void*)winusb_device;
/* create an interface object */