summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 08:39:45 -0400
committerJonathan Cameron <jic23@kernel.org>2015-05-31 12:22:56 -0400
commit121b5e505fe86ea52603c946865d658a5fe8130b (patch)
treeca199605bfc1aa3be8e15dc3e56dd16849312149 /tools/iio
parent63f05c855f3825b89b92cd21df0415e6e32af3dd (diff)
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: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/iio_utils.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 6daf98fdde1a..1c0ca2f89e18 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -334,6 +334,7 @@ int build_channel_array(const char *device_dir,
334 if (sysfsfp == NULL) { 334 if (sysfsfp == NULL) {
335 free(filename); 335 free(filename);
336 ret = -errno; 336 ret = -errno;
337 count--;
337 goto error_cleanup_array; 338 goto error_cleanup_array;
338 } 339 }
339 fscanf(sysfsfp, "%i", &current_enabled); 340 fscanf(sysfsfp, "%i", &current_enabled);
@@ -353,6 +354,7 @@ int build_channel_array(const char *device_dir,
353 if (current->name == NULL) { 354 if (current->name == NULL) {
354 free(filename); 355 free(filename);
355 ret = -ENOMEM; 356 ret = -ENOMEM;
357 count--;
356 goto error_cleanup_array; 358 goto error_cleanup_array;
357 } 359 }
358 /* Get the generic and specific name elements */ 360 /* Get the generic and specific name elements */
@@ -360,6 +362,8 @@ int build_channel_array(const char *device_dir,
360 &current->generic_name); 362 &current->generic_name);
361 if (ret) { 363 if (ret) {
362 free(filename); 364 free(filename);
365 free(current->name);
366 count--;
363 goto error_cleanup_array; 367 goto error_cleanup_array;
364 } 368 }
365 ret = asprintf(&filename, 369 ret = asprintf(&filename,