Skip to content

Commit

Permalink
tools: iio: Set caller's ci_array pointer to NULL after free
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
jasaw authored and jic23 committed Aug 8, 2015
1 parent bdb25b0 commit 6b20f40
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/iio/iio_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ int build_channel_array(const char *device_dir,
free((*ci_array)[i].generic_name);
}
free(*ci_array);
*ci_array = NULL;
*counter = 0;
error_close_dir:
if (dp)
if (closedir(dp) == -1)
Expand Down

0 comments on commit 6b20f40

Please sign in to comment.