Hi Greg,
On 20/09/23 5:01 pm, Greg Kroah-Hartman wrote:
5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Luo <haoluo@xxxxxxxxxx>
[ 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@xxxxxxxxxx>
Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
Link: https://lore.kernel.org/bpf/20230822193840.1509809-1-haoluo@xxxxxxxxxx
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
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 b8849812449c3..343018632d2d1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4202,6 +4202,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);
This patch introduces a build failure.
libbpf.c: In function 'bpf_object__close':
libbpf.c:4205:22: error: 'struct bpf_object' has no member named
'btf_vmlinux'
4205 | btf__free(obj->btf_vmlinux);
| ^~
This struct member "btf_vmlinux" is added in commit a6ed02cac690
("libbpf: Load btf_vmlinux only once per object.") which is not in 5.4.y
So I think we should drop this patch.
Thanks,
Harshit
btf_ext__free(obj->btf_ext);
for (i = 0; i < obj->nr_maps; i++) {