diff options
author | Angus Gratton <gus@projectgus.com> | 2015-04-28 16:49:57 +1000 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2016-03-01 23:13:42 -0800 |
commit | 926148d5f72d838cabafabe61e02871bc8b6854e (patch) | |
tree | 56d2ecebbd7ac16d781a66a0d3409ccb73d766c1 | |
parent | 1d54ee1b6687c532eca75925f56eb12e2a34ce42 (diff) | |
download | libusb-926148d5f72d838cabafabe61e02871bc8b6854e.tar.gz |
Windows: Fix dev_interface_path memory leak when reusing device ref
windows_get_device_list was leaking dev_interface_path (in either of two
possible places) when a pre-existing device reference was reused.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/os/windows_winusb.c | 25 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 15 insertions, 12 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index a5c70db..b716278 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -1264,7 +1264,7 @@ static int set_hid_interface(struct libusb_context *ctx, struct libusb_device *d for (i = 0; i < priv->hid->nb_interfaces; i++) { if (safe_strcmp(priv->usb_interface[i].path, dev_interface_path) == 0) { usbi_dbg("interface[%d] already set to %s", i, dev_interface_path); - return LIBUSB_SUCCESS; + return LIBUSB_ERROR_ACCESS; } } @@ -1548,6 +1548,9 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered // Setup device switch (pass) { case HCD_PASS: + // If the hcd has already been setup, don't do it again + if (priv->path != NULL) + break; dev->bus_number = (uint8_t)(i + 1); // bus 0 is reserved for disconnected dev->device_address = 0; dev->num_configurations = 0; @@ -1607,21 +1610,21 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered } break; default: // HID_PASS and later - if (parent_priv->apib->id == USB_API_HID) { - usbi_dbg("setting HID interface for [%lX]:", parent_dev->session_data); - r = set_hid_interface(ctx, parent_dev, dev_interface_path); - if (r != LIBUSB_SUCCESS) - LOOP_BREAK(r); - - dev_interface_path = NULL; - } else if (parent_priv->apib->id == USB_API_COMPOSITE) { - usbi_dbg("setting composite interface for [%lX]:", parent_dev->session_data); - switch (set_composite_interface(ctx, parent_dev, dev_interface_path, dev_id_path, api, sub_api)) { + if (parent_priv->apib->id == USB_API_HID || parent_priv->apib->id == USB_API_COMPOSITE) { + if (parent_priv->apib->id == USB_API_HID) { + usbi_dbg("setting HID interface for [%lX]:", parent_dev->session_data); + r = set_hid_interface(ctx, parent_dev, dev_interface_path); + } else { + usbi_dbg("setting composite interface for [%lX]:", parent_dev->session_data); + r = set_composite_interface(ctx, parent_dev, dev_interface_path, dev_id_path, api, sub_api); + } + switch (r) { case LIBUSB_SUCCESS: dev_interface_path = NULL; break; case LIBUSB_ERROR_ACCESS: // interface has already been set => make sure dev_interface_path is freed then + r = LIBUSB_SUCCESS; break; default: LOOP_BREAK(r); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 28b8b2e..bd5f24a 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11077 +#define LIBUSB_NANO 11078 |