linux-stable/tools/bpf/bpftool
Quentin Monnet 0b95aaa493 bpftool: Avoid leaking the JSON writer prepared for program metadata
[ Upstream commit e89ef634f8 ]

Bpftool creates a new JSON object for writing program metadata in plain
text mode, regardless of metadata being present or not. Then this writer
is freed if any metadata has been found and printed, but it leaks
otherwise. We cannot destroy the object unconditionally, because the
destructor prints an undesirable line break. Instead, make sure the
writer is created only after we have found program metadata to print.

Found with valgrind.

Fixes: aff52e685e ("bpftool: Support dumping metadata")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211022094743.11052-1-quentin@isovalent.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18 14:04:10 +01:00
..
bash-completion bpftool: Add sock_release help info for cgroup attach/prog load command 2021-06-03 09:00:51 +02:00
Documentation bpftool: Add sock_release help info for cgroup attach/prog load command 2021-06-03 09:00:51 +02:00
skeleton tools, bpftool: Remove two unused variables. 2020-10-29 15:23:18 +01:00
.gitignore tools/bpftool: Generalize BPF skeleton support and generate vmlinux.h 2020-06-22 17:01:48 -07:00
btf.c bpftool: Fix maybe-uninitialized warnings 2021-05-14 09:50:29 +02:00
btf_dumper.c tools/bpftool: Fix compilation warnings in 32-bit mode 2020-08-13 16:45:41 -07:00
cfg.c tools, bpftool: Poison and replace kernel integer typedefs 2020-05-11 21:20:46 +02:00
cfg.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00
cgroup.c bpftool: Add sock_release help info for cgroup attach/prog load command 2021-06-03 09:00:51 +02:00
common.c bpftool: Check malloc return value in mount_bpffs_for_pin 2021-07-28 14:35:37 +02:00
feature.c tools, bpftool: Avoid array index warnings. 2020-10-29 15:22:57 +01:00
gen.c tools/bpftool: Remove libbpf_internal.h usage in bpftool 2020-08-18 18:38:25 -07:00
iter.c tools/bpf: Support new uapi for map element bpf iterator 2020-08-06 16:39:14 -07:00
jit_disasm.c bpftool: Properly close va_list 'ap' by va_end() on error 2021-07-25 14:36:21 +02:00
json_writer.c bpftool: Support dumping metadata 2020-09-15 18:28:27 -07:00
json_writer.h bpftool: Support dumping metadata 2020-09-15 18:28:27 -07:00
link.c bpftool: Implement link_query for bpf iterators 2020-08-21 14:01:39 -07:00
main.c tools/bpftool: Fix error return code in do_batch() 2021-07-14 16:56:20 +02:00
main.h tools/bpftool: Fix compilation warnings in 32-bit mode 2020-08-13 16:45:41 -07:00
Makefile Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-10-05 18:40:01 -07:00
map.c bpftool: Fix maybe-uninitialized warnings 2021-05-14 09:50:29 +02:00
map_perf_ring.c tools, bpftool: Poison and replace kernel integer typedefs 2020-05-11 21:20:46 +02:00
net.c bpftool: Fix compilation failure for net.o with older glibc 2021-01-17 14:17:03 +01:00
netlink_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.h tools: bpftool: dual license all files 2018-12-13 12:08:44 +01:00
perf.c tools, bpftool: Clean subcommand help messages 2020-06-01 14:38:18 -07:00
pids.c tools/bpftool: Fix PID fetching with a lot of results 2020-12-08 16:45:20 +01:00
prog.c bpftool: Avoid leaking the JSON writer prepared for program metadata 2021-11-18 14:04:10 +01:00
struct_ops.c tools, bpftool: Clean subcommand help messages 2020-06-01 14:38:18 -07:00
tracelog.c tools: bpftool: add an option to prevent auto-mount of bpffs, tracefs 2018-12-18 14:47:17 +01:00
xlated_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
xlated_dumper.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00