From b6a2f595151dc6de850f7bc0e2aa5aec3db80213 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 27 Sep 2016 12:35:55 -0700 Subject: [PATCH] adb: fix IOKit handle leaks on OS X. Bug: https://code.google.com/p/android/issues/detail?id=219085 Test: Removed sleep in RunLoopThread, compared before/after this patch Change-Id: Ia65bbedfb7d47bdb02bdfb69778784e5e855900b --- adb/usb_osx.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/adb/usb_osx.cpp b/adb/usb_osx.cpp index ddde454d1..adcbb3e66 100644 --- a/adb/usb_osx.cpp +++ b/adb/usb_osx.cpp @@ -177,6 +177,7 @@ AndroidInterfaceAdded(io_iterator_t iterator) kr = (*iface)->GetDevice(iface, &usbDevice); if (kIOReturnSuccess != kr || !usbDevice) { LOG(ERROR) << "Couldn't grab device from interface (" << std::hex << kr << ")"; + (*iface)->Release(iface); continue; } @@ -191,6 +192,7 @@ AndroidInterfaceAdded(io_iterator_t iterator) (void)IOObjectRelease(usbDevice); if ((kIOReturnSuccess != kr) || (!plugInInterface)) { LOG(ERROR) << "Unable to create a device plug-in (" << std::hex << kr << ")"; + (*iface)->Release(iface); continue; } @@ -200,6 +202,7 @@ AndroidInterfaceAdded(io_iterator_t iterator) (*plugInInterface)->Release(plugInInterface); if (result || !dev) { LOG(ERROR) << "Couldn't create a device interface (" << std::hex << result << ")"; + (*iface)->Release(iface); continue; } @@ -211,6 +214,8 @@ AndroidInterfaceAdded(io_iterator_t iterator) if (kr == KERN_SUCCESS) { devpath = android::base::StringPrintf("usb:%" PRIu32 "X", locationId); if (IsKnownDevice(devpath)) { + (*dev)->Release(dev); + (*iface)->Release(iface); continue; } }