From 842c719c2f21920b6af33035fb5280eea2c1efe6 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 5 Mar 2010 00:13:51 +0000 Subject: fixed unref of devices that already exist (Travis Robinson) --- libusb/os/windows_usb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index b3d7743..5b0ae89 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -759,7 +759,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs USB_HUB_NAME_FIXED s_hubname; USB_NODE_CONNECTION_INFORMATION conn_info; USB_NODE_INFORMATION hub_node; - bool is_hcd; + bool is_hcd, need_unref = false; int i, r; LPCWSTR wstr; char *tmp_str = NULL, *path_str = NULL; @@ -792,7 +792,10 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs for (i = 1, r = LIBUSB_SUCCESS; ; i++) { // safe loop: release all dynamic resources - safe_unref_device(dev); + if (need_unref) { + safe_unref_device(dev); + need_unref = false; + } safe_free(tmp_str); safe_free(path_str); safe_closehandle(handle); @@ -906,6 +909,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs if ((dev = usbi_alloc_device(ctx, session_id)) == NULL) { LOOP_BREAK(LIBUSB_ERROR_NO_MEM); } + need_unref = true; LOOP_CHECK(initialize_device(dev, busnum, devaddr, path_str, i, conn_info.CurrentConfigurationValue, parent_dev)); -- cgit v1.2.1