mirror of
https://github.com/RPCS3/libusb.git
synced 2026-01-31 01:25:19 +01:00
Windows: Fix possible memory leak when caching descriptors fails
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define LIBUSB_NANO 11195
|
||||
#define LIBUSB_NANO 11196
|
||||
|
||||
Reference in New Issue
Block a user