Commit 121b5e50 authored by Hartmut Knaack's avatar Hartmut Knaack Committed by Jonathan Cameron

tools:iio:iio_utils: fix allocation handling

In build_channel_array(), count needs to be decreased in more places since
current->name and current->generic_name would be freed on the error path,
although they have not been allocated, yet.
This also requires to free current->name, when it is allocated, but
current->generic_name is not yet allocated.
Signed-off-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 63f05c85
...@@ -334,6 +334,7 @@ int build_channel_array(const char *device_dir, ...@@ -334,6 +334,7 @@ int build_channel_array(const char *device_dir,
if (sysfsfp == NULL) { if (sysfsfp == NULL) {
free(filename); free(filename);
ret = -errno; ret = -errno;
count--;
goto error_cleanup_array; goto error_cleanup_array;
} }
fscanf(sysfsfp, "%i", &current_enabled); fscanf(sysfsfp, "%i", &current_enabled);
...@@ -353,6 +354,7 @@ int build_channel_array(const char *device_dir, ...@@ -353,6 +354,7 @@ int build_channel_array(const char *device_dir,
if (current->name == NULL) { if (current->name == NULL) {
free(filename); free(filename);
ret = -ENOMEM; ret = -ENOMEM;
count--;
goto error_cleanup_array; goto error_cleanup_array;
} }
/* Get the generic and specific name elements */ /* Get the generic and specific name elements */
...@@ -360,6 +362,8 @@ int build_channel_array(const char *device_dir, ...@@ -360,6 +362,8 @@ int build_channel_array(const char *device_dir,
&current->generic_name); &current->generic_name);
if (ret) { if (ret) {
free(filename); free(filename);
free(current->name);
count--;
goto error_cleanup_array; goto error_cleanup_array;
} }
ret = asprintf(&filename, ret = asprintf(&filename,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment