tools: iio: Set caller's ci_array pointer to NULL after free
authorJoo Aun Saw <jasaw@dius.com.au>
Fri, 24 Jul 2015 15:23:28 +0000 (01:23 +1000)
committerJonathan Cameron <jic23@kernel.org>
Sat, 8 Aug 2015 18:51:39 +0000 (19:51 +0100)
On error, caller's ci_array is freed and set to NULL to avoid
potential double free if some other user of this code is not
sufficiently careful. Counter is reset to zero for consistency.

Signed-off-by: Joo Aun Saw <jasaw@dius.com.au>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
tools/iio/iio_utils.c

index 4bbd6e7959cdad471e6cb0bdbf0d0cda915cd743..8475b832ee397914a71fd8be781ccc3f043e45a0 100644 (file)
@@ -526,6 +526,8 @@ error_cleanup_array:
                free((*ci_array)[i].generic_name);
        }
        free(*ci_array);
+       *ci_array = NULL;
+       *counter = 0;
 error_close_dir:
        if (dp)
                if (closedir(dp) == -1)