summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorHao Luo <haoluo@google.com>2023-08-22 22:38:40 +0300
committerAndrii Nakryiko <andrii@kernel.org>2023-08-23 02:16:31 +0300
commit29d67fdebc42af6466d1909c60fdd1ef4f3e5240 (patch)
tree80d1f564e0b6db1fb1e71104bea4a30b6924a9f5 /tools/lib
parent87680ac7979177a34ca39b5a35a2ed94209cd20f (diff)
downloadlinux-29d67fdebc42af6466d1909c60fdd1ef4f3e5240.tar.xz
libbpf: Free btf_vmlinux when closing bpf_object
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
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b8afe2f5bc93..4c3967d94b6d 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8423,6 +8423,7 @@ void bpf_object__close(struct bpf_object *obj)
bpf_object__elf_finish(obj);
bpf_object_unload(obj);
btf__free(obj->btf);
+ btf__free(obj->btf_vmlinux);
btf_ext__free(obj->btf_ext);
for (i = 0; i < obj->nr_maps; i++)