]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
bpf, libbpf: fixing leak when kernel does not support btf
authorNikita V. Shirokov <tehnerd@tehnerd.com>
Fri, 8 Mar 2019 05:18:14 +0000 (05:18 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 8 Mar 2019 20:16:36 +0000 (21:16 +0100)
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>
tools/lib/bpf/libbpf.c

index f5eb60379c8d9d005587bc1e1c85daf4c28d167b..d5b830d606010ad33fd780a514e3684f07d92506 100644 (file)
@@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
                        if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
                                pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
                                           BTF_ELF_SEC, PTR_ERR(obj->btf));
+                               if (!IS_ERR(obj->btf))
+                                       btf__free(obj->btf);
                                obj->btf = NULL;
                        }
                } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {