Browse Source

Check return for LIBMTP_Open_Raw_Device_Uncached

The LIBMTP_Open_Raw_Device_Uncached function may return NULL if
an error occurs when attempting to open the device. We need to
check for that possibility.

Incenp-bug-id: 6
(This patch will prevent the crash observed in that bug, but it
does not fix the fact that LIBMTP sometimes fails to open the
device.)
develop
Damien Goutte-Gattat 5 years ago
parent
commit
8a253b8520
  1. 8
      src/scheme-libmtp.c

8
src/scheme-libmtp.c

@ -54,7 +54,9 @@ find_mtp_device(const char *wanted_serial)
for ( i = 0, device = NULL; i < n && device == NULL; i++ ) {
char *serial;
device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]));
if ( ! (device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]))) )
continue;
if ( (serial = LIBMTP_Get_Serialnumber(device)) == NULL ||
strcmp(serial, wanted_serial) != 0 ) {
LIBMTP_Release_Device(device);
@ -400,7 +402,9 @@ gfsec_scheme_libmtp_get_supports(gfsec_supports_list_t *list)
for ( i = 0, device = NULL; i < n && device == NULL; i++ ) {
char *serial, *name;
device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]));
if ( ! (device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]))) )
continue;
serial = LIBMTP_Get_Serialnumber(device);
name = LIBMTP_Get_Friendlyname(device);

Loading…
Cancel
Save