mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 04:52:02 +08:00
drivers/usbdev: fix used after free when calling close after uninitialize
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -533,6 +533,12 @@ static int usbdev_fs_close(FAR struct file *filep)
|
||||
{
|
||||
kmm_free(fs->eps);
|
||||
fs->eps = NULL;
|
||||
if (!fs->registered)
|
||||
{
|
||||
FAR struct usbdev_fs_driver_s *alloc = container_of(
|
||||
fs, FAR struct usbdev_fs_driver_s, dev);
|
||||
kmm_free(alloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1411,6 +1417,17 @@ void usbdev_fs_classuninitialize(FAR struct usbdevclass_driver_s *classdev)
|
||||
}
|
||||
else
|
||||
{
|
||||
FAR struct usbdev_fs_dev_s *fs = &alloc->dev;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < fs->devinfo.nendpoints; i++)
|
||||
{
|
||||
if (fs->eps != NULL && fs->eps[i].crefs > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
kmm_free(alloc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user