summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-04-13 08:25:52 -0700
committerGravatar Matt Colyer2009-04-13 08:25:52 -0700
commit708029463ed4f1e8aa83ca1c98a0ea658247ef7a (patch)
tree778ca7f25ea85684ade0f48c65f2985413a4e185
parent09f72b498f71b7aed3c248282b41ad04d2df399d (diff)
downloadlibimobiledevice-708029463ed4f1e8aa83ca1c98a0ea658247ef7a.tar.gz
libimobiledevice-708029463ed4f1e8aa83ca1c98a0ea658247ef7a.tar.bz2
Check for set usb_device in iphone_free_device to avoid libusb segfault
Signed-off-by: Matt Colyer <matt@colyer.name>
-rw-r--r--src/iphone.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/iphone.c b/src/iphone.c
index 6eb56f7..c2a79bb 100644
--- a/src/iphone.c
+++ b/src/iphone.c
@@ -230,13 +230,15 @@ iphone_error_t iphone_free_device(iphone_device_t device)
unsigned char buf[512];
// read final package(s)
- do {
- bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 800);
- if (bytes > 0) {
- log_debug_msg("iphone_free_device: final read returned\n");
- log_debug_buffer(buf, bytes);
- }
- } while (bytes > 0);
+ if (device->device != NULL) {
+ do {
+ bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 800);
+ if (bytes > 0) {
+ log_debug_msg("iphone_free_device: final read returned\n");
+ log_debug_buffer(buf, bytes);
+ }
+ } while (bytes > 0);
+ }
if (device->buffer) {
free(device->buffer);