Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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;
}
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++) {
-#define LIBUSB_NANO 11195
+#define LIBUSB_NANO 11196