Hi,

Thanks for the patch, pushed to master.

On 06/24/2013 01:31 PM, Toby Gray wrote:
> The Windows CE device allocation code has always had a bug where it would
> leak references to devices when they are allocated. This commit removes the
> reference leak.
>
> This leak was highlighted by the new hotplug code which now triggers a NULL
> pointer dereference if not all devices are unreferenced before libusb_exit
> is called.
> ---
>   libusb/os/wince_usb.c |   10 ++++------
>   1 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/libusb/os/wince_usb.c b/libusb/os/wince_usb.c
> index d8e8f55..76b559d 100644
> --- a/libusb/os/wince_usb.c
> +++ b/libusb/os/wince_usb.c
> @@ -341,10 +341,10 @@ static int wince_get_device_list(
>       UKW_DEVICE devices[MAX_DEVICE_COUNT];
>       struct discovered_devs * new_devices = *discdevs;
>       DWORD count = 0, i;
> -     struct libusb_device *dev;
> +     struct libusb_device *dev = NULL;
>       unsigned char bus_addr, dev_addr;
>       unsigned long session_id;
> -     BOOL success, need_unref = FALSE;
> +     BOOL success;
>       DWORD release_list_offset = 0;
>       int r = LIBUSB_SUCCESS;
>
> @@ -378,7 +378,6 @@ static int wince_get_device_list(
>                               r = LIBUSB_ERROR_NO_MEM;
>                               goto err_out;
>                       }
> -                     need_unref = TRUE;
>                       r = init_device(dev, devices[i], bus_addr, dev_addr);
>                       if (r < 0)
>                               goto err_out;
> @@ -391,14 +390,13 @@ static int wince_get_device_list(
>                       r = LIBUSB_ERROR_NO_MEM;
>                       goto err_out;
>               }
> -             need_unref = FALSE;
> +             safe_unref_device(dev);
>       }
>       *discdevs = new_devices;
>       return r;
>   err_out:
>       *discdevs = new_devices;
> -     if (need_unref)
> -             libusb_unref_device(dev);
> +     safe_unref_device(dev);
>       // Release the remainder of the unprocessed device list.
>       // The devices added to new_devices already will still be passed up to 
> libusb,
>       // which can dispose of them at its leisure.
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to