Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/gusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ static int get_string_descriptor (struct gusb_device * device, unsigned char ind
struct usb_descriptor_header * descriptor = (struct usb_descriptor_header *)data;

if (descriptor->bLength > ret) {
void * ptr = realloc(data, descriptor->bLength * sizeof(*data));
size_t len = descriptor->bLength;
void * ptr = realloc(data, len * sizeof(*data));
if (ptr == NULL) {
PRINT_ERROR_ALLOC_FAILED("realloc");
free(data);
Expand All @@ -566,7 +567,7 @@ static int get_string_descriptor (struct gusb_device * device, unsigned char ind
data = ptr;

ret = libusb_control_transfer(device->devh, LIBUSB_ENDPOINT_IN,
LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | index, descriptors->langId0.wData[0], data, descriptor->bLength, DEFAULT_TIMEOUT);
LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | index, descriptors->langId0.wData[0], data, len, DEFAULT_TIMEOUT);
if (ret < 0) {
PRINT_ERROR_LIBUSB("libusb_control_transfer", ret);
free(data);
Expand Down Expand Up @@ -1270,17 +1271,18 @@ static int set_notifiers(struct gusb_device * device, libusb_context * ctx) {
for (i = 0; pollfds[i] != NULL && ret != -1; ++i) {
ret = pollfd_register(device, pollfds[i]->fd, pollfds[i]->events);
}
free(pollfds);

if (ret == -1) {
// roll-back
for (i = i - 1; i >= 0; --i) {
pollfd_remove(device, pollfds[i]->fd);
}
libusb_set_pollfd_notifiers(ctx, NULL, NULL, NULL);
free(pollfds);
return -1;
}

free(pollfds);
return 0;
}
#endif
Expand Down