aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
authorNikita V. Shirokov <tehnerd@tehnerd.com>2019-03-08 00:18:14 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2019-03-08 15:16:36 -0500
commit243b4cdab981d7004bee56c38e18a29da32ef104 (patch)
tree0a2e293600e43da600aaaccfbcf9fdea971d5870 /tools/lib/bpf/libbpf.c
parent20182390c4134478d795a096ddb8dddcc648e28a (diff)
bpf, libbpf: fixing leak when kernel does not support btf
We could end up in situation when we have object file w/ all btf info, but kernel does not support btf yet. In this situation currently libbpf just set obj->btf to NULL w/o freeing it first. This patch is fixing it by making sure to run btf__free first. Fixes: d29d87f7e612 ("btf: separate btf creation and loading") Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index f5eb60379c8d..d5b830d60601 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
838 if (IS_ERR(obj->btf) || btf__load(obj->btf)) { 838 if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
839 pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n", 839 pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
840 BTF_ELF_SEC, PTR_ERR(obj->btf)); 840 BTF_ELF_SEC, PTR_ERR(obj->btf));
841 if (!IS_ERR(obj->btf))
842 btf__free(obj->btf);
841 obj->btf = NULL; 843 obj->btf = NULL;
842 } 844 }
843 } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) { 845 } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {