usb_modeswitch.cpp: fix use after free.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #13185
This commit is contained in:
Murai Takashi 2017-01-09 05:37:34 +09:00 committed by Adrien Destugues
parent baf9ae1d47
commit a1fdbe5bb2

View File

@ -531,11 +531,13 @@ my_device_added(usb_device newDevice, void **cookie)
mutex_init(&device->lock, DRIVER_NAME " device lock");
device->notify = create_sem(0, DRIVER_NAME " callback notify");
if (device->notify < B_OK) {
sem_id id = create_sem(0, DRIVER_NAME " callback notify");
if (id < B_OK) {
mutex_destroy(&device->lock);
free(device);
return device->notify;
return id;
} else {
device->notify = id;
}
mutex_lock(&gDeviceListLock);