Some bugfixes and better error checking

This commit is contained in:
2019-12-15 11:29:35 -05:00
parent ad4b82c5c2
commit ff0984d1c8

View File

@@ -58,14 +58,24 @@ int get_device_bundle(struct pwned_device *dev)
if(ret == LIBUSB_SUCCESS) if(ret == LIBUSB_SUCCESS)
{ {
checkm8_debug_indent("\topening device and returning success\n"); checkm8_debug_indent("\topening device and returning success\n");
libusb_open(dev->bundle->device, &dev->bundle->handle); ret = libusb_open(dev->bundle->device, &dev->bundle->handle);
libusb_set_auto_detach_kernel_driver(dev->bundle->handle, 1); if(ret == 0)
{
libusb_set_auto_detach_kernel_driver(dev->bundle->handle, 1);
}
else
{
checkm8_debug_indent("\tfailed to open device\n");
libusb_exit(dev->bundle->ctx);
free(dev->bundle->descriptor);
}
return ret;
} }
else else
{ {
checkm8_debug_indent("\tcould not find a matching device\n"); checkm8_debug_indent("\tcould not find a matching device\n");
libusb_exit(dev->bundle->ctx); libusb_exit(dev->bundle->ctx);
free(dev->bundle->ctx);
free(dev->bundle->descriptor); free(dev->bundle->descriptor);
dev->bundle->ctx = NULL; dev->bundle->ctx = NULL;
@@ -93,7 +103,6 @@ int release_device_bundle(struct pwned_device *dev)
{ {
checkm8_debug_indent("\texiting context\n");; checkm8_debug_indent("\texiting context\n");;
libusb_exit(dev->bundle->ctx); libusb_exit(dev->bundle->ctx);
free(dev->bundle->ctx);
dev->bundle->ctx = NULL; dev->bundle->ctx = NULL;
} }