iio: Fix possible crash on device removal
Check whether we managed to open the index file instead of crashing. #0 0x00007f31843660c7 in __vfscanf_internal () at /lib64/libc.so.6 #1 0x00007f31843657ed in __isoc99_fscanf () at /lib64/libc.so.6 #2 0x0000560bfd6b942b in build_channel_array (counter=0x560bfdea01c8, device_dir=0x560bfde90810 "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/0003:273F:1008.0044/HID-SENSOR-200041.2.auto/iio:device0") at iio-buffer-utils.c:320 #3 0x0000560bfd6b942b in build_channels (data=0x560bfdea01b0) at iio-buffer-utils.c:739 (gdb) frame 2 #2 0x0000560bfd6b942b in build_channel_array (counter=0x560bfdea01c8, device_dir=0x560bfde90810 "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/0003:273F:1008.0044/HID-SENSOR-200041.2.auto/iio:device0") at iio-buffer-utils.c:320 320 fscanf (sysfsfp, "%u", ¤t->index); (gdb) p sysfsfp $1 = (FILE *) 0x0
This commit is contained in:
@@ -318,6 +318,10 @@ build_channel_array (const char *device_dir,
|
||||
g_free (index_name);
|
||||
|
||||
sysfsfp = fopen (filename, "r");
|
||||
if (sysfsfp == NULL) {
|
||||
ret = -errno;
|
||||
goto error;
|
||||
}
|
||||
fscanf (sysfsfp, "%u", ¤t->index);
|
||||
fclose (sysfsfp);
|
||||
g_free (filename);
|
||||
|
Reference in New Issue
Block a user