tools api: Avoid potential double free
authorIan Rogers <irogers@google.com>
Mon, 9 Oct 2023 18:39:17 +0000 (11:39 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 17:01:57 +0000 (10:01 -0700)
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>
tools/lib/api/io.h

index 9fc429d2852d783f9bcf84102e172a945800e370..a77b74c5fb655a8c7b65c293ba0dd563f34f8569 100644 (file)
@@ -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;
 }