summaryrefslogtreecommitdiff
path: root/libusb/os/darwin_usb.c
diff options
context:
space:
mode:
authorVitali Lovich <vlovich@aliph.com>2011-09-05 12:39:00 +0000
committerVitali Lovich <vlovich@aliph.com>2011-09-05 12:44:58 +0100
commite28b097e75a48b5c08c3130ab05a27d1943128b2 (patch)
tree45a9d119a11ab4f0a5d6007650e7999972ee0bb8 /libusb/os/darwin_usb.c
parentaa282fe9d5d150b3cd0dec12cd99c3fb594dda84 (diff)
downloadlibusb-e28b097e75a48b5c08c3130ab05a27d1943128b2.tar.gz
Darwin: Fix #108 crash when a device is unplugged
Diffstat (limited to 'libusb/os/darwin_usb.c')
-rw-r--r--libusb/os/darwin_usb.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 169fa1a..9691827 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -222,6 +222,7 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
io_service_t device;
long location;
+ bool locationValid;
CFTypeRef locationCF;
UInt32 message;
@@ -231,10 +232,19 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
/* get the location from the i/o registry */
locationCF = IORegistryEntryCreateCFProperty (device, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault, 0);
- CFNumberGetValue(locationCF, kCFNumberLongType, &location);
- CFRelease (locationCF);
IOObjectRelease (device);
+ if (!locationCF)
+ continue;
+
+ locationValid = CFGetTypeID(locationCF) == CFNumberGetTypeID() &&
+ CFNumberGetValue(locationCF, kCFNumberLongType, &location);
+
+ CFRelease (locationCF);
+
+ if (!locationValid)
+ continue;
+
usbi_mutex_lock(&ctx->open_devs_lock);
list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) {
dpriv = (struct darwin_device_priv *)handle->dev->os_priv;