Blob Blame History Raw
From: Andrii Nakryiko <andriin@fb.com>
Date: Tue, 28 Apr 2020 18:21:08 -0700
Subject: libbpf: Fix huge memory leak in libbpf_find_vmlinux_btf_id()
Patch-mainline: v5.8-rc1
Git-commit: 3521ffa2ee9a48c3236c93f54ae11c074490ebce
References: bsc#1177028

BTF object wasn't freed.

Fixes: a6ed02cac690 ("libbpf: Load btf_vmlinux only once per object.")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: KP Singh <kpsingh@google.com>
Link: https://lore.kernel.org/bpf/20200429012111.277390-9-andriin@fb.com
Acked-by: Gary Lin <glin@suse.com>
---
 tools/lib/bpf/libbpf.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6422,6 +6422,7 @@ int libbpf_find_vmlinux_btf_id(const cha
 			       enum bpf_attach_type attach_type)
 {
 	struct btf *btf;
+	int err;
 
 	btf = libbpf_find_kernel_btf();
 	if (IS_ERR(btf)) {
@@ -6429,7 +6430,9 @@ int libbpf_find_vmlinux_btf_id(const cha
 		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)