public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Free btf_vmlinux when closing bpf_object
@ 2023-08-22 19:38 Hao Luo
  2023-08-22 23:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Luo @ 2023-08-22 19:38 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann, martin.lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh,
	Stanislav Fomichev, Jiri Olsa, Hao Luo

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>
---
 tools/lib/bpf/libbpf.c | 1 +
 1 file changed, 1 insertion(+)

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++)
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: Free btf_vmlinux when closing bpf_object
  2023-08-22 19:38 [PATCH bpf-next] libbpf: Free btf_vmlinux when closing bpf_object Hao Luo
@ 2023-08-22 23:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-22 23:20 UTC (permalink / raw)
  To: Hao Luo
  Cc: bpf, andrii, ast, daniel, martin.lau, song, yonghong.song,
	john.fastabend, kpsingh, sdf, jolsa

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue, 22 Aug 2023 12:38:40 -0700 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] libbpf: Free btf_vmlinux when closing bpf_object
    https://git.kernel.org/bpf/bpf-next/c/29d67fdebc42

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-22 23:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22 19:38 [PATCH bpf-next] libbpf: Free btf_vmlinux when closing bpf_object Hao Luo
2023-08-22 23:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox