From: Hartmut Knaack Date: Sun, 31 May 2015 12:39:45 +0000 (+0200) Subject: tools:iio:iio_utils: fix allocation handling X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=121b5e505fe86ea52603c946865d658a5fe8130b;p=linux-beck.git 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 Signed-off-by: Jonathan Cameron --- 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, if (sysfsfp == NULL) { free(filename); ret = -errno; + count--; goto error_cleanup_array; } fscanf(sysfsfp, "%i", ¤t_enabled); @@ -353,6 +354,7 @@ int build_channel_array(const char *device_dir, if (current->name == NULL) { free(filename); ret = -ENOMEM; + count--; goto error_cleanup_array; } /* Get the generic and specific name elements */ @@ -360,6 +362,8 @@ int build_channel_array(const char *device_dir, ¤t->generic_name); if (ret) { free(filename); + free(current->name); + count--; goto error_cleanup_array; } ret = asprintf(&filename,