From 9aaaa2b924cbc5efa578e7522977935251e3318f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Mar 2017 15:15:50 +0200 Subject: [PATCH] IOS/USB: Unref libusb devices manually --- Source/Core/Core/IOS/USB/Host.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/USB/Host.cpp b/Source/Core/Core/IOS/USB/Host.cpp index f29d470f1a..0ad6bc9cce 100644 --- a/Source/Core/Core/IOS/USB/Host.cpp +++ b/Source/Core/Core/IOS/USB/Host.cpp @@ -145,17 +145,25 @@ bool USBHost::AddNewDevices(std::set& new_devices, DeviceChangeHooks& hooks libusb_get_device_descriptor(device, &descriptor); if (!SConfig::GetInstance().IsUSBDeviceWhitelisted( {descriptor.idVendor, descriptor.idProduct})) + { + libusb_unref_device(device); continue; + } auto usb_device = std::make_unique(device, descriptor); if (!ShouldAddDevice(*usb_device)) + { + libusb_unref_device(device); continue; + } const u64 id = usb_device->GetId(); new_devices.insert(id); if (AddDevice(std::move(usb_device)) || always_add_hooks) hooks.emplace(GetDeviceById(id), ChangeEvent::Inserted); + else + libusb_unref_device(device); } - libusb_free_device_list(list, 1); + libusb_free_device_list(list, 0); } #endif return true;