tools:iio: catch errors in string allocation
This patch catches errors in string allocation in generic_buffer.c,
iio_event_monitor.c, iio_utils.c and lsiio.c.
Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c
index 65a2385..daa6c53 100644
--- a/tools/iio/lsiio.c
+++ b/tools/iio/lsiio.c
@@ -107,7 +107,12 @@
if (check_prefix(ent->d_name, type_device)) {
char *dev_dir_name;
- asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
+ if (asprintf(&dev_dir_name, "%s%s", iio_dir,
+ ent->d_name) < 0) {
+ printf("Memory allocation failed\n");
+ goto error_close_dir;
+ }
+
dump_one_device(dev_dir_name);
free(dev_dir_name);
if (verblevel >= VERBLEVEL_SENSORS)
@@ -119,11 +124,17 @@
if (check_prefix(ent->d_name, type_trigger)) {
char *dev_dir_name;
- asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
+ if (asprintf(&dev_dir_name, "%s%s", iio_dir,
+ ent->d_name) < 0) {
+ printf("Memory allocation failed\n");
+ goto error_close_dir;
+ }
+
dump_one_trigger(dev_dir_name);
free(dev_dir_name);
}
}
+error_close_dir:
closedir(dp);
}