Skip to content

Commit 29d67fd

Browse files
haoluo1022anakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 87680ac commit 29d67fd

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,6 +8423,7 @@ void bpf_object__close(struct bpf_object *obj)
84238423
bpf_object__elf_finish(obj);
84248424
bpf_object_unload(obj);
84258425
btf__free(obj->btf);
8426+
btf__free(obj->btf_vmlinux);
84268427
btf_ext__free(obj->btf_ext);
84278428

84288429
for (i = 0; i < obj->nr_maps; i++)

0 commit comments

Comments
 (0)