mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-18 15:29:06 +08:00
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
This commit is contained in:
committed by
Andrii Nakryiko
parent
4920031c88
commit
bd25fc7df1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user