diff mbox series

[v2,bpf-next,08/11] libbpf: fix huge memory leak in libbpf_find_vmlinux_btf_id()

Message ID 20200429012111.277390-9-andriin@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series Fix libbpf and selftest issues detected by ASAN | expand

Commit Message

Andrii Nakryiko April 29, 2020, 1:21 a.m. UTC
BTF object wasn't freed.

Cc: KP Singh <kpsingh@google.com>
Fixes: a6ed02cac690 ("libbpf: Load btf_vmlinux only once per object.")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/libbpf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8e1dc6980fac..a0f943e6b7bb 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6672,6 +6672,7 @@  int libbpf_find_vmlinux_btf_id(const char *name,
 			       enum bpf_attach_type attach_type)
 {
 	struct btf *btf;
+	int err;
 
 	btf = libbpf_find_kernel_btf();
 	if (IS_ERR(btf)) {
@@ -6679,7 +6680,9 @@  int libbpf_find_vmlinux_btf_id(const char *name,
 		return -EINVAL;
 	}
 
-	return __find_vmlinux_btf_id(btf, name, attach_type);
+	err = __find_vmlinux_btf_id(btf, name, attach_type);
+	btf__free(btf);
+	return err;
 }
 
 static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)