bpftool: Fix memory leak in prog_dump()
authorQuentin Monnet <quentin@isovalent.com>
Wed, 10 Nov 2021 11:46:27 +0000 (11:46 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:03:07 +0000 (11:03 +0100)
commit77d19bad301facba3fdb33da69584e000c6985f1
treee8ddf8c53db1280ad596e8a55c8be8cd51da5d5a
parent9f3cbc3ba5adf9973e7252039f5ca2cae945baed
bpftool: Fix memory leak in prog_dump()

[ Upstream commit ebbd7f64a3fbe9e0f235e39fc244ee9735e2a52a ]

Following the extraction of prog_dump() from do_dump(), the struct btf
allocated in prog_dump() is no longer freed on error; the struct
bpf_prog_linfo is not freed at all. Make sure we release them before
exiting the function.

Fixes: ec2025095cf6 ("bpftool: Match several programs with same tag")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211110114632.24537-2-quentin@isovalent.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/bpf/bpftool/prog.c