Windows: Fix possible memory leak when caching descriptors fails

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
This commit is contained in:
Chris Dickens
2017-03-26 20:37:41 -07:00
parent beb0d61b92
commit 05b0b55b75
3 changed files with 13 additions and 5 deletions

View File

@@ -974,6 +974,16 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle
LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
memcpy(priv->config_descriptor[i], cd_data, cd_data->wTotalLength);
}
// Any failure will result in dev->num_configurations being forced to 0.
// We need to release any memory that may have been allocated for config
// descriptors that were successfully retrieved, otherwise that memory
// will be leaked
if (r != LIBUSB_SUCCESS) {
for (i = 0; i < dev->num_configurations; i++)
free(priv->config_descriptor[i]);
}
return r;
}

View File

@@ -244,10 +244,8 @@ static inline void windows_device_priv_release(struct libusb_device *dev)
int i;
free(p->path);
if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
for (i = 0; i < dev->num_configurations; i++)
free(p->config_descriptor[i]);
}
for (i = 0; i < dev->num_configurations; i++)
free(p->config_descriptor[i]);
free(p->config_descriptor);
free(p->hid);
for (i = 0; i < USB_MAXINTERFACES; i++) {

View File

@@ -1 +1 @@
#define LIBUSB_NANO 11195
#define LIBUSB_NANO 11196