tools/iio: Add memory allocation failure check for trigger_name
authorZhu Jun <zhujun2@cmss.chinamobile.com>
Wed, 28 Aug 2024 09:31:29 +0000 (02:31 -0700)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 3 Sep 2024 17:49:44 +0000 (18:49 +0100)
Added a check to handle memory allocation failure for `trigger_name`
and return `-ENOMEM`.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Link: https://patch.msgid.link/20240828093129.3040-1-zhujun2@cmss.chinamobile.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
tools/iio/iio_generic_buffer.c

index 0d0a7a19d6f952dc81dbf76c446571b6b4f42c30..9ef5ee087eda367ff2c01923802238421bdbf7eb 100644 (file)
@@ -498,6 +498,10 @@ int main(int argc, char **argv)
                        return -ENOMEM;
                }
                trigger_name = malloc(IIO_MAX_NAME_LENGTH);
+               if (!trigger_name) {
+                       ret = -ENOMEM;
+                       goto error;
+               }
                ret = read_sysfs_string("name", trig_dev_name, trigger_name);
                free(trig_dev_name);
                if (ret < 0) {