diff options
author | Nathan Hjelm <hjelmn@me.com> | 2013-04-25 21:12:45 -0600 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-05-15 20:43:35 +0200 |
commit | 91deff8f6bf3041855f014533dfaa81b75e0b5f9 (patch) | |
tree | 13cce1b4a90c5d8eb12bd5a6f9f48cf101518334 /libusb/os/darwin_usb.c | |
parent | 8dfb979df12cdf95d4156156cee02bc2f64adb16 (diff) | |
download | libusb-91deff8f6bf3041855f014533dfaa81b75e0b5f9.tar.gz |
darwin: fix memory leaks in the darwin backend.
There were two memory leaks in the darwin backend:
- A CFString allocated by IORegistryEntryCreateCFProperty in darwin_get_interface()
was not released.
- The runloop is retained by darwin_open() but was not release by darwin_close().
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'libusb/os/darwin_usb.c')
-rw-r--r-- | libusb/os/darwin_usb.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index babfa28..4cc2298 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -100,6 +100,8 @@ static const char *darwin_error_str (int result) { return "data overrun"; case kIOReturnCannotWire: return "physical memory can not be wired down"; + case kIOReturnNoResources: + return "out of resources"; default: return "unknown error"; } @@ -287,7 +289,6 @@ static void darwin_devices_attached (void *ptr, io_iterator_t add_devices) { static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) { struct libusb_device *dev = NULL; struct libusb_context *ctx; - struct darwin_device_priv *dpriv; io_service_t device; bool locationValid; @@ -320,7 +321,6 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) { if (!dev) { continue; } - dpriv = (struct darwin_device_priv *) dev->os_priv; /* signal the core that this device has been disconnected. the core will tear down this device when the reference count reaches 0 */ @@ -414,6 +414,9 @@ static void *darwin_event_thread_main (void *arg0) { usbi_dbg ("thread exiting"); + /* remove the notification cfsource */ + CFRunLoopRemoveSource(runloop, libusb_notification_cfsource, kCFRunLoopDefaultMode); + /* delete notification port */ IONotificationPortDestroy (libusb_notification_port); @@ -929,6 +932,7 @@ static void darwin_close (struct libusb_device_handle *dev_handle) { CFRunLoopRemoveSource (libusb_darwin_acfl, priv->cfSource, kCFRunLoopDefaultMode); CFRelease (priv->cfSource); priv->cfSource = NULL; + CFRelease (libusb_darwin_acfl); } if (priv->is_open) { @@ -1012,6 +1016,8 @@ static int darwin_get_interface (usb_device_t **darwin_device, uint8_t ifc, io_s CFNumberGetValue(bInterfaceNumberCF, kCFNumberIntType, &bInterfaceNumber); + CFRelease(bInterfaceNumberCF); + if ((uint8_t) bInterfaceNumber == ifc) { break; } |