gpio: fix incorrect assignment of *cinfos in mraa_get_chip_infos
*cinfos in mraa_get_chip_infos is not set in case of mraa_get_chip_info_by_name failure which happens on access of /dev/gpiochip* files which leads to memory free by invalid pointer in *cinfos. As example, it can be easy recreated with non-root run of mraa-gpio: test@iot2050-debian:~$ mraa-gpio free(): invalid pointer Aborted Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>
This commit is contained in:
committed by
Tom Ingleby
parent
8185e983e1
commit
9ea6cd2dc6
@@ -431,6 +431,8 @@ mraa_get_chip_infos(mraa_gpiod_chip_info*** cinfos)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*cinfos = cinfo;
|
||||||
|
|
||||||
/* Get chip info for all gpiochips present in the platform */
|
/* Get chip info for all gpiochips present in the platform */
|
||||||
for (i = 0; i < num_chips; i++) {
|
for (i = 0; i < num_chips; i++) {
|
||||||
cinfo[i] = mraa_get_chip_info_by_name(dirs[i]->d_name);
|
cinfo[i] = mraa_get_chip_info_by_name(dirs[i]->d_name);
|
||||||
@@ -440,7 +442,5 @@ mraa_get_chip_infos(mraa_gpiod_chip_info*** cinfos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*cinfos = cinfo;
|
|
||||||
|
|
||||||
return num_chips;
|
return num_chips;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user