summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-10-09 11:39:17 -0700
committerNamhyung Kim <namhyung@kernel.org>2023-10-12 10:01:57 -0700
commitc4b5140c6eac2f757d9706c6c783b60554c48cb7 (patch)
treec4020b92d38b6393b1e4e7666cd322b719d197cc /tools/lib
parent7875c72c8b0566590c888a2420d7e8fc12f67154 (diff)
tools api: Avoid potential double free
io__getline will free the line on error but it doesn't clear the out argument. This may lead to the line being freed twice, like in tools/perf/util/srcline.c as detected by clang-tidy. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: llvm@lists.linux.dev Cc: Ming Wang <wangming01@loongson.cn> Cc: Tom Rix <trix@redhat.com> Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/r/20231009183920.200859-17-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/api/io.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/tools/lib/api/io.h b/tools/lib/api/io.h
index 9fc429d2852d..a77b74c5fb65 100644
--- a/tools/lib/api/io.h
+++ b/tools/lib/api/io.h
@@ -180,6 +180,7 @@ static inline ssize_t io__getline(struct io *io, char **line_out, size_t *line_l
return line_len;
err_out:
free(line);
+ *line_out = NULL;
return -ENOMEM;
}