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)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 6 Oct 2020 18:10:20 +0000 (11:10 -0700)
commita0f2b7acb4b1d29127ff99c714233b973afd1411
treeba743ced8c89cd6f1ed8a44f8b443b2d79aaef6c
parentdca4121cdc48027320c95cbce8f5e81160aa4afe
libbpf: Close map fd if init map slots failed

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
tools/lib/bpf/libbpf.c