diff options
author | Shuyi Cheng <chengshuyi@linux.alibaba.com> | 2021-07-13 20:42:38 +0800 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2021-07-16 13:22:47 -0700 |
commit | 18353c87e0e0440d4c7c746ed740738bbc1b538e (patch) | |
tree | 671a7fee2cf31dca2d5a840c96ab94bf3c59a0be | |
parent | 1373ff59955621b7e71e7a1152036c93a5780c11 (diff) |
libbpf: Fix the possible memory leak on error
If the strdup() fails then we need to call bpf_object__close(obj) to
avoid a resource leak.
Fixes: 166750bc1dd2 ("libbpf: Support libbpf-provided extern variables")
Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1626180159-112996-3-git-send-email-chengshuyi@linux.alibaba.com
-rw-r--r-- | tools/lib/bpf/libbpf.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 8bff28fc3fc9..17bc922f543f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -7649,8 +7649,10 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz, kconfig = OPTS_GET(opts, kconfig, NULL); if (kconfig) { obj->kconfig = strdup(kconfig); - if (!obj->kconfig) - return ERR_PTR(-ENOMEM); + if (!obj->kconfig) { + err = -ENOMEM; + goto out; + } } err = bpf_object__elf_init(obj); |