libbpf: Close map fd if init map slots failed
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 6 Oct 2020 02:13:43 +0000 (10:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:08:21 +0000 (10:08 +0100)
commit6afdaf29e4c2394e94a5df5c747673c2343d9764
tree75c927a90705f7d7548e9d1c89673b35eda60cc2
parente1ec1c25b00ea9734c6881e86b3075458cf83e60
libbpf: Close map fd if init map slots failed

[ Upstream commit a0f2b7acb4b1d29127ff99c714233b973afd1411 ]

Previously we forgot to close the map fd if bpf_map_update_elem()
failed during map slot init, which will leak map fd.

Let's move map slot initialization to new function init_map_slots() to
simplify the code. And close the map fd if init slot failed.

Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201006021345.3817033-2-liuhangbin@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/libbpf.c