Skip to content

Commit

Permalink
Fix libusb config descriptor leak
Browse files Browse the repository at this point in the history
The descriptor received from libusb_get_active_config_descriptor was
never freed. Thus, when opening a channel repeatedly, more and more
memory was leaked (tested with valgrind).
  • Loading branch information
nioncode authored and LudovicRousseau committed Aug 27, 2018
1 parent 3374848 commit 06ae975
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ccid_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
usb_interface = get_ccid_usb_interface(config_desc, &num);
if (usb_interface == NULL)
{
libusb_free_config_descriptor(config_desc);
(void)libusb_close(dev_handle);
if (0 == num)
DEBUG_CRITICAL3("Can't find a CCID interface on %d/%d",
Expand All @@ -618,6 +619,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
device_descriptor = get_ccid_device_descriptor(usb_interface);
if (NULL == device_descriptor)
{
libusb_free_config_descriptor(config_desc);
(void)libusb_close(dev_handle);
DEBUG_CRITICAL3("Unable to find the device descriptor for %d/%d",
bus_number, device_address);
Expand All @@ -628,6 +630,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
interface = usb_interface->altsetting->bInterfaceNumber;
if (interface_number >= 0 && interface != interface_number)
{
libusb_free_config_descriptor(config_desc);
/* an interface was specified and it is not the
* current one */
DEBUG_INFO3("Found interface %d but expecting %d",
Expand All @@ -644,6 +647,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
r = libusb_claim_interface(dev_handle, interface);
if (r < 0)
{
libusb_free_config_descriptor(config_desc);
(void)libusb_close(dev_handle);
DEBUG_CRITICAL4("Can't claim interface %d/%d: %s",
bus_number, device_address, libusb_error_name(r));
Expand All @@ -660,6 +664,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
/* check for firmware bugs */
if (ccid_check_firmware(&desc))
{
libusb_free_config_descriptor(config_desc);
(void)libusb_close(dev_handle);
return_value = STATUS_UNSUCCESSFUL;
goto end2;
Expand Down Expand Up @@ -760,6 +765,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
else
usbDevice[reader_index].multislot_extension = NULL;

libusb_free_config_descriptor(config_desc);
goto end;
}
}
Expand Down

0 comments on commit 06ae975

Please sign in to comment.