Commit 0b95aaa4 authored by Quentin Monnet's avatar Quentin Monnet Committed by Greg Kroah-Hartman
Browse files

bpftool: Avoid leaking the JSON writer prepared for program metadata



[ Upstream commit e89ef634 ]

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: aff52e68 ("bpftool: Support dumping metadata")
Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211022094743.11052-1-quentin@isovalent.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 7cd4af99
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment