Skip to content

Commit 8758401

Browse files
chengshuyigregkh
authored andcommitted
libbpf: Fix the possible memory leak on error
[ Upstream commit 18353c8 ] If the strdup() fails then we need to call bpf_object__close(obj) to avoid a resource leak. Fixes: 166750b ("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6d213fb commit 8758401

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎tools/lib/bpf/libbpf.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7365,8 +7365,10 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz,
73657365
kconfig = OPTS_GET(opts, kconfig, NULL);
73667366
if (kconfig) {
73677367
obj->kconfig = strdup(kconfig);
7368-
if (!obj->kconfig)
7369-
return ERR_PTR(-ENOMEM);
7368+
if (!obj->kconfig) {
7369+
err = -ENOMEM;
7370+
goto out;
7371+
}
73707372
}
73717373

73727374
err = bpf_object__elf_init(obj);

0 commit comments

Comments
 (0)