Private
Public Access
2
0

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:
Ivan Mikhaylov
2022-03-23 16:23:58 +00:00
committed by Tom Ingleby
parent 8185e983e1
commit 9ea6cd2dc6

View File

@@ -431,6 +431,8 @@ mraa_get_chip_infos(mraa_gpiod_chip_info*** cinfos)
return -1;
}
*cinfos = cinfo;
/* Get chip info for all gpiochips present in the platform */
for (i = 0; i < num_chips; i++) {
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;
}