summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--device/usb/usb_device_handle_impl.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/device/usb/usb_device_handle_impl.cc b/device/usb/usb_device_handle_impl.cc
index 716c6c1..cf6ebfb 100644
--- a/device/usb/usb_device_handle_impl.cc
+++ b/device/usb/usb_device_handle_impl.cc
@@ -782,8 +782,14 @@ UsbDeviceHandleImpl::UsbDeviceHandleImpl(
UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
// This class is RefCountedThreadSafe and so the destructor may be called on
- // any thread.
- libusb_close(handle_);
+ // any thread. libusb is not safe to reentrancy so be sure not to try to close
+ // the device from inside a transfer completion callback.
+ if (blocking_task_runner_->RunsTasksOnCurrentThread()) {
+ libusb_close(handle_);
+ } else {
+ blocking_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&libusb_close, handle_));
+ }
}
void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread(