瀏覽代碼

tools: iio: Set caller's ci_array pointer to NULL after free

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>
Joo Aun Saw 10 年之前
父節點
當前提交
6b20f40679
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      tools/iio/iio_utils.c

+ 2 - 0
tools/iio/iio_utils.c

@@ -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)