]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Free btf_vmlinux when closing bpf_object
authorHao Luo <haoluo@google.com>
Tue, 22 Aug 2023 19:38:40 +0000 (12:38 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Sep 2023 09:11:03 +0000 (11:11 +0200)
commitd5feaef143b6217657f07e4d9f13a2a2da6a4ee1
treeb2afd968c2e5b2969cd4d403bb6db15333610e92
parentb9a175e3b250b0dc6e152988040aa5014e98e61e
libbpf: Free btf_vmlinux when closing bpf_object

[ Upstream commit 29d67fdebc42af6466d1909c60fdd1ef4f3e5240 ]

I hit a memory leak when testing bpf_program__set_attach_target().
Basically, set_attach_target() may allocate btf_vmlinux, for example,
when setting attach target for bpf_iter programs. But btf_vmlinux
is freed only in bpf_object_load(), which means if we only open
bpf object but not load it, setting attach target may leak
btf_vmlinux.

So let's free btf_vmlinux in bpf_object__close() anyway.

Signed-off-by: Hao Luo <haoluo@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230822193840.1509809-1-haoluo@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/libbpf.c