libbpf: Fix the possible memory leak on error
authorShuyi Cheng <chengshuyi@linux.alibaba.com>
Tue, 13 Jul 2021 12:42:38 +0000 (20:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Sep 2021 07:50:32 +0000 (09:50 +0200)
commit6ca0b4089166c6e03b95e48866931d23f4ff542f
tree0af789c5187e6875d0a9290e3777d7b7c072e482
parentf1673e85254d3dae8f595c0367cd33c73530952e
libbpf: Fix the possible memory leak on error

[ Upstream commit 18353c87e0e0440d4c7c746ed740738bbc1b538e ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/libbpf.c